@@ -28,21 +28,17 @@ const (
2828)
2929
3030type directoryCache struct {
31- baseDir string
31+ baseDir * paths. Path
3232 ttl time.Duration
3333}
3434
35- func (dc * directoryCache ) basePath () * paths.Path {
36- return paths .New (dc .baseDir )
37- }
38-
3935func (dc * directoryCache ) isExpired (key string ) time.Duration {
4036 modTime , _ := dc .modTime (key )
4137 return dc .ttl - time .Since (modTime )
4238}
4339
4440func (dc * directoryCache ) modTime (key string ) (time.Time , error ) {
45- fileInfo , err := dc .basePath () .Join (key , lastUsedFileName ).Stat ()
41+ fileInfo , err := dc .baseDir .Join (key , lastUsedFileName ).Stat ()
4642 if err != nil {
4743 // folders with a missing last used file are not purged
4844 return time .Now ().Add (time .Minute ), err
@@ -58,9 +54,9 @@ func (dc *directoryCache) GetOrCreate(key string, value time.Time) (time.Time, e
5854 existing = false
5955 }
6056
61- subDir := dc .basePath () .Join (key )
57+ subDir := dc .baseDir .Join (key )
6258 err = subDir .MkdirAll ()
63- if err != nil || existing {
59+ if err != nil {
6460 return modTime , err
6561 }
6662 err = subDir .Join (lastUsedFileName ).WriteFile ([]byte {})
@@ -71,7 +67,7 @@ func (dc *directoryCache) GetOrCreate(key string, value time.Time) (time.Time, e
7167}
7268
7369func (dc * directoryCache ) Purge () error {
74- files , err := dc .basePath () .ReadDir ()
70+ files , err := dc .baseDir .ReadDir ()
7571 if err != nil {
7672 return err
7773 }
@@ -88,16 +84,15 @@ func (dc *directoryCache) removeIfExpired(dir *paths.Path) {
8884 if lifeExpectancy > 0 {
8985 return
9086 }
91- subDir := dc .basePath ().Join (dir .Base ())
92- logrus .Tracef (`Purging cache directory "%s". Expired by %s\n` , subDir , lifeExpectancy )
93- err := subDir .RemoveAll ()
87+ logrus .Tracef (`Purging cache directory "%s". Expired by %s\n` , dir , lifeExpectancy )
88+ err := dir .RemoveAll ()
9489
9590 if err != nil {
96- logrus .Tracef (`Error while pruning cache directory "%s".\n%s\n` , subDir , errors .WithStack (err ))
91+ logrus .Tracef (`Error while pruning cache directory "%s".\n%s\n` , dir , errors .WithStack (err ))
9792 }
9893}
9994
100- func newDirectoryCache (baseDir string , ttl time.Duration ) * directoryCache {
95+ func newDirectoryCache (baseDir * paths. Path , ttl time.Duration ) * directoryCache {
10196 return & directoryCache {
10297 baseDir : baseDir ,
10398 ttl : ttl ,
0 commit comments