Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
snapstate: add support for refresh.schedule=managed #4161
Merged
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
120a1bb
interfaces: add "refresh-schedule" attribute to snapd-control
mvo5 707b8ac
snapstate: add support for "refresh.schedule=managed" via core config
mvo5 ed5b2dc
address review feedback
mvo5 2b49e46
remove commonInterface.SanitizePlug() again, YAGNI
mvo5 beaea1f
address review feedback
mvo5 51cb644
snapstate,devicestate: move refreshScheduleManaged into devicestate a…
mvo5 881ec0b
devicestate: use SnapDeclaration() in refreshScheduleManaged
mvo5 c53683d
Merge branch 'fakestore-new-snap-decl' into tmp
mvo5 c26a1e4
add integration test for snapd-control with manage
mvo5 f786253
snapd.refresh.service.in: do not do emergency refresh if schedule is …
mvo5 24c7da0
Merge remote-tracking branch 'upstream/master' into refresh-control-m…
mvo5 9364d10
data/systemd/snapd.refresh.service.in: fix silly typo
mvo5 b8f14cc
snapstate: ask store for refresh-hints every 24h
mvo5 ed821ba
tests: add missing test for CanSetRefreshScheduleManaged()
mvo5 250caf8
address review feedback from bboozzoo (thanks!)
mvo5 c13562e
snapstate: move checkRefreshHints() to be run always
mvo5 4ba03de
tests: improve interfaces-snapd-control-with-manage
mvo5 36b10fc
snapstate: move refresh hints handling into its own struct
mvo5 138fb4d
Merge remote-tracking branch 'upstream/master' into refresh-control-m…
mvo5 c8d78c9
interfaces-snapd-control-with-manage: install jq (if missing) before …
mvo5 40caf89
cmd/snap-seccomp: fix uid/gid restrictions tests on Arch
bboozzoo 1ddff6a
tests: set -e, -o pipefail in prepare-restore.sh
zyga ec0462e
tests: remove obsolete workaround
zyga 28ea7c0
apparmor: generate the snap-confine re-exec profile for AppArmor{Part…
mvo5 ce5fd02
tests: simplify copying of cached snaps
zyga 12ece01
tests: cache snaps to $TESTSLIB/cache
zyga 68783fe
snap: use existing files in `snap download` if digest/size matches
mvo5 b2cba77
tests: merge prepare-project.sh into prepare-restore.sh
zyga b34653a
tests: move source/import statements to the top
zyga a76d338
tests: quote ${archive_compression}
zyga 38cd927
tests: don't cp --link, it doesn't handle xdev
zyga 57419a2
tests/lib: fix shellcheck errors
bboozzoo 9aa0470
Merge branch 'snapmgr-autorefresh-refactor' into refresh-control-managed
mvo5 2e2967d
Merge remote-tracking branch 'upstream/master' into refresh-control-m…
mvo5 74bf338
snapstate, devicestate: refactor so that we only need to hook snapsta…
mvo5 fe8bc54
address review feedback and add extra test for snap debug can-manage-…
mvo5
Jump to file or symbol
Failed to load files and symbols.
Viewing a subset of changes. View all
snapstate: move refresh hints handling into its own struct
- Loading branch information...
commit 36b10fc142a9558a1e0db8b543d7d591e6c9feb4
mvo5
committed
Nov 21, 2017
| @@ -0,0 +1,70 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
| +/* | ||
| + * Copyright (C) 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 snapstate | ||
| + | ||
| +import ( | ||
| + "time" | ||
| + | ||
| + "github.com/snapcore/snapd/overlord/state" | ||
| + "github.com/snapcore/snapd/store" | ||
| +) | ||
| + | ||
| +var refreshHintsDelay = time.Duration(24 * time.Hour) | ||
| + | ||
| +type refreshHints struct { | ||
| + state *state.State | ||
| +} | ||
| + | ||
| +func newRefreshHints(st *state.State) *refreshHints { | ||
| + return &refreshHints{state: st} | ||
| +} | ||
| + | ||
| +func (r *refreshHints) lastRefresh() (time.Time, error) { | ||
| + var lastRefresh time.Time | ||
| + if err := r.state.Get("last-refresh-hints", &lastRefresh); err != nil && err != state.ErrNoState { | ||
| + return time.Time{}, err | ||
| + } | ||
| + return lastRefresh, nil | ||
| +} | ||
| + | ||
| +func (r *refreshHints) needsUpdate() (bool, error) { | ||
| + t, err := r.lastRefresh() | ||
| + if err != nil { | ||
| + return false, err | ||
| + } | ||
| + return t.Before(time.Now().Add(-refreshHintsDelay)), nil | ||
| +} | ||
| + | ||
| +func (r *refreshHints) refresh() error { | ||
| + _, _, _, err := refreshCandidates(r.state, nil, nil, &store.RefreshOptions{RefreshManaged: true}) | ||
| + r.state.Set("last-refresh-hints", time.Now()) | ||
| + return err | ||
| +} | ||
| + | ||
| +func (r *refreshHints) Ensure() error { | ||
| + needsUpdate, err := r.needsUpdate() | ||
| + if err != nil { | ||
| + return err | ||
| + } | ||
| + if !needsUpdate { | ||
| + return nil | ||
| + } | ||
| + return r.refresh() | ||
| +} |