Skip to content

Commit

Permalink
incorporate review
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed May 26, 2023
1 parent 814638e commit 65d1833
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/common/accessio/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ var (
_ RootedCache = (*blobCache)(nil)
)

// ACCESS_SUFFIX is the suffix of an additional blob related
// file used to track the last access time by its modification time,
// because Go does not support a platform independent way to access the
// last access time attribute of a filesystem.
const ACCESS_SUFFIX = ".acc"

func NewDefaultBlobCache(fss ...vfs.FileSystem) (BlobCache, error) {
var err error
fs := DefaultedFileSystem(nil, fss...)
Expand Down Expand Up @@ -215,12 +221,12 @@ func (c *blobCache) Cleanup(p common.Printer, before *time.Time, dryrun bool) (c
return 0, 0, 0, 0, 0, 0, err
}
for _, e := range entries {
if strings.HasSuffix(e.Name(), ".acc") {
if strings.HasSuffix(e.Name(), ACCESS_SUFFIX) {
continue
}
base := vfs.Join(fs, path, e.Name())
if before != nil && !before.IsZero() {
fi, err := fs.Stat(base + ".acc")
fi, err := fs.Stat(base + ACCESS_SUFFIX)
if err != nil {
if !vfs.IsErrNotExist(err) {
if p != nil {
Expand Down Expand Up @@ -248,7 +254,7 @@ func (c *blobCache) Cleanup(p common.Printer, before *time.Time, dryrun bool) (c
fsize += e.Size()
continue
}
fs.RemoveAll(base + ".acc")
fs.RemoveAll(base + ACCESS_SUFFIX)
}
cnt++
size += e.Size()
Expand All @@ -270,9 +276,9 @@ func (c *blobCache) GetBlobData(digest digest.Digest) (int64, DataAccess, error)
path := common.DigestToFileName(digest)
fi, err := c.cache.Stat(path)
if err == nil {
vfs.WriteFile(c.cache, path+".acc", []byte{}, 0o600)
vfs.WriteFile(c.cache, path+ACCESS_SUFFIX, []byte{}, 0o600)
// now := time.Now()
// c.cache.Chtimes(path+".acc", now, now)
// c.cache.Chtimes(path+ACCESS_SUFFIX, now, now)
return fi.Size(), DataAccessForFile(c.cache, path), nil
}
if os.IsNotExist(err) {
Expand Down Expand Up @@ -341,7 +347,7 @@ func (c *blobCache) AddBlob(blob BlobAccess) (int64, digest.Digest, error) {
err = c.cache.Rename(tmp, target)
}
c.cache.Remove(tmp)
vfs.WriteFile(c.cache, target+".acc", []byte{}, 0o600)
vfs.WriteFile(c.cache, target+ACCESS_SUFFIX, []byte{}, 0o600)
return size, digest, err
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/open-component-model/ocm/pkg/generics"
)

// ParseDeltaTime parses a time diff relative to the actual
// time and returns the resulting time.
func ParseDeltaTime(s string, past bool) (time.Time, error) {
var t time.Time

Expand Down

0 comments on commit 65d1833

Please sign in to comment.