Skip to content

Commit

Permalink
respository: update root before snapshot (#1001)
Browse files Browse the repository at this point in the history
* respository: update root before snapshot

* repository: fix unit test

Co-authored-by: SIGSEGV <[email protected]>
  • Loading branch information
AstroProfundis and lucklove authored Dec 28, 2020
1 parent 24289a3 commit 357cd71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,13 @@ func (r *V1Repository) ensureManifests() error {
verbose.Log("Ensure manifests finished in %s", time.Since(start))
}(time.Now())

// Update snapshot.
snapshot, err := r.updateLocalSnapshot()
if err != nil {
// Update root before anything else.
if err := r.updateLocalRoot(); err != nil {
return errors.Trace(err)
}

// Update root.
err = r.updateLocalRoot()
// Update snapshot.
snapshot, err := r.updateLocalSnapshot()
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -353,7 +352,7 @@ func (r *V1Repository) updateLocalRoot() error {
url := FnameWithVersion(v1manifest.ManifestURLRoot, oldRoot.Version+1)
nextManifest, err := r.fetchManifestWithKeyStore(url, &newRoot, maxRootSize, &keyStore)
if err != nil {
// Break if we have read the newest version.
// Break if we have read the latest version.
if errors.Cause(err) == ErrNotFound {
break
}
Expand Down Expand Up @@ -825,7 +824,7 @@ func (r *V1Repository) BinaryPath(installPath string, componentID string, versio
specVersion = component.Nightly
}

// We need yanked version because we may install that version before it was yanked
// We need yanked version because we may have installed that version before it was yanked
versionItem, ok := component.VersionListWithYanked(r.PlatformString())[specVersion]
if !ok {
return "", errors.Errorf("no version: %s", version)
Expand Down
6 changes: 3 additions & 3 deletions pkg/repository/v1_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,19 @@ func TestEnsureManifests(t *testing.T) {
assert.NotContains(t, local.Saved, v1manifest.ManifestFilenameRoot)

// Happy update
root2, priv2 := rootManifest(t)
root2, priv2 := rootManifest(t) // generate new root key
root, _ := repo.loadRoot()
root2.Version = root.Version + 1
mirror.Resources["/43.root.json"] = serialize(t, root2, priv, priv2)

rootMeta := snapshot.Meta[v1manifest.ManifestURLRoot]
rootMeta.Version = root2.Version
snapshot.Meta[v1manifest.ManifestURLRoot] = rootMeta
snapStr = serialize(t, snapshot, priv)
snapStr = serialize(t, snapshot, priv2) // sign snapshot with new key
ts.Meta[v1manifest.ManifestURLSnapshot].Hashes[v1manifest.SHA256] = hash(snapStr)
ts.Version++
mirror.Resources[v1manifest.ManifestURLSnapshot] = snapStr
mirror.Resources[v1manifest.ManifestURLTimestamp] = serialize(t, ts, priv)
mirror.Resources[v1manifest.ManifestURLTimestamp] = serialize(t, ts, priv2)
local.Saved = []string{}

err = repo.ensureManifests()
Expand Down

0 comments on commit 357cd71

Please sign in to comment.