mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
fix(meta): fixes for LastUpdated and TaggedTimestamp (#3754)
1. Parse repos without metadata in ParseStorage The timestamp check in ParseStorage was skipping repos that exist in storage but don't have metadata. When GetRepoLastUpdated returns zero time (no metadata), we should always parse the repo to create its metadata. Check if metaLastUpdated is zero before comparing timestamps. If zero, always parse regardless of storageLastUpdated. 2. Change the logic of how LastUpdated is computed in RepoSummary It is not the latest tagged timestamp from the available images or the last updated image created timestamp, based on whichever is the latest. Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
@@ -1182,7 +1182,12 @@ func (bdw *BoltDB) ResetRepoReferences(repo string, tagsToKeep map[string]bool)
|
||||
repoMetaBlob := buck.Get([]byte(repo))
|
||||
|
||||
protoRepoMeta, err := unmarshalProtoRepoMeta(repo, repoMetaBlob)
|
||||
if err != nil && !errors.Is(err, zerr.ErrRepoMetaNotFound) {
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrRepoMetaNotFound) {
|
||||
// Repo doesn't exist, nothing to reset
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -308,6 +308,43 @@ func TestWrapperErrors(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("ResetRepoReferences", func() {
|
||||
Convey("repo doesn't exist - returns early without error", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Verify repo doesn't exist
|
||||
_, err := boltdbWrapper.GetRepoMeta(ctx, "nonexistent-repo")
|
||||
So(err, ShouldNotBeNil)
|
||||
So(errors.Is(err, zerr.ErrRepoMetaNotFound), ShouldBeTrue)
|
||||
|
||||
// ResetRepoReferences should return early without error
|
||||
err = boltdbWrapper.ResetRepoReferences("nonexistent-repo", nil)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify repo still doesn't exist
|
||||
_, err = boltdbWrapper.GetRepoMeta(ctx, "nonexistent-repo")
|
||||
So(err, ShouldNotBeNil)
|
||||
So(errors.Is(err, zerr.ErrRepoMetaNotFound), ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("repo doesn't exist with tagsToKeep - returns early without error", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Verify repo doesn't exist
|
||||
_, err := boltdbWrapper.GetRepoMeta(ctx, "nonexistent-repo2")
|
||||
So(err, ShouldNotBeNil)
|
||||
So(errors.Is(err, zerr.ErrRepoMetaNotFound), ShouldBeTrue)
|
||||
|
||||
// ResetRepoReferences should return early without error even with tagsToKeep
|
||||
tagsToKeep := map[string]bool{"tag1": true}
|
||||
err = boltdbWrapper.ResetRepoReferences("nonexistent-repo2", tagsToKeep)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify repo still doesn't exist
|
||||
_, err = boltdbWrapper.GetRepoMeta(ctx, "nonexistent-repo2")
|
||||
So(err, ShouldNotBeNil)
|
||||
So(errors.Is(err, zerr.ErrRepoMetaNotFound), ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("unmarshalProtoRepoMeta error", func() {
|
||||
err := setRepoMeta("repo", badProtoBlob, boltdbWrapper.DB)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Reference in New Issue
Block a user