代码拉取完成,页面将自动刷新
同步操作将从 tupelo-shen/mysnapd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2016-2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package assertstate
import (
"gitee.com/mysnapcore/mysnapd/asserts"
"gitee.com/mysnapcore/mysnapd/logger"
"gitee.com/mysnapcore/mysnapd/overlord/auth"
"gitee.com/mysnapcore/mysnapd/overlord/snapstate"
"gitee.com/mysnapcore/mysnapd/overlord/state"
)
// TODO: snapstate also has this, move to auth, or change a bit the approach now that we have DeviceAndAuthContext in the store?
func userFromUserID(st *state.State, userID int) (*auth.UserState, error) {
if userID == 0 {
return nil, nil
}
return auth.User(st, userID)
}
// handleUnsupported behaves as a fallback in case of bugs, we do ask
// the store to filter unsupported formats!
func handleUnsupported(db asserts.RODatabase) func(ref *asserts.Ref, unsupportedErr error) error {
return func(ref *asserts.Ref, unsupportedErr error) error {
if _, err := ref.Resolve(db.Find); err != nil {
// nothing there yet or any other error
return unsupportedErr
}
// we keep the old one, but log the issue
logger.Noticef("Cannot update assertion %v: %v", ref, unsupportedErr)
return nil
}
}
// doFetch fetches and save assertions. If a batch is passed then it's not committed.
// If no batch is passed, one is created and committed.
func doFetch(s *state.State, userID int, deviceCtx snapstate.DeviceContext, batch *asserts.Batch, fetching func(asserts.Fetcher) error) error {
// TODO: once we have a bulk assertion retrieval endpoint this approach will change
db := cachedDB(s)
// don't commit batch if it was passed in since caller might want to do it later
var commitBatch bool
if batch == nil {
batch = asserts.NewBatch(handleUnsupported(db))
commitBatch = true
}
user, err := userFromUserID(s, userID)
if err != nil {
return err
}
sto := snapstate.Store(s, deviceCtx)
retrieve := func(ref *asserts.Ref) (asserts.Assertion, error) {
// TODO: ignore errors if already in db?
return sto.Assertion(ref.Type, ref.PrimaryKey, user)
}
s.Unlock()
err = batch.Fetch(db, retrieve, fetching)
s.Lock()
if err != nil {
return err
}
// TODO: trigger w. caller a global validity check if a is revoked
// (but try to save as much possible still), or err is a check error
if commitBatch {
return batch.CommitTo(db, nil)
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。