@@ -28,21 +28,17 @@ const (
28
28
)
29
29
30
30
type directoryCache struct {
31
- baseDir string
31
+ baseDir * paths. Path
32
32
ttl time.Duration
33
33
}
34
34
35
- func (dc * directoryCache ) basePath () * paths.Path {
36
- return paths .New (dc .baseDir )
37
- }
38
-
39
35
func (dc * directoryCache ) isExpired (key string ) time.Duration {
40
36
modTime , _ := dc .modTime (key )
41
37
return dc .ttl - time .Since (modTime )
42
38
}
43
39
44
40
func (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 ()
46
42
if err != nil {
47
43
// folders with a missing last used file are not purged
48
44
return time .Now ().Add (time .Minute ), err
@@ -58,9 +54,9 @@ func (dc *directoryCache) GetOrCreate(key string, value time.Time) (time.Time, e
58
54
existing = false
59
55
}
60
56
61
- subDir := dc .basePath () .Join (key )
57
+ subDir := dc .baseDir .Join (key )
62
58
err = subDir .MkdirAll ()
63
- if err != nil || existing {
59
+ if err != nil {
64
60
return modTime , err
65
61
}
66
62
err = subDir .Join (lastUsedFileName ).WriteFile ([]byte {})
@@ -71,7 +67,7 @@ func (dc *directoryCache) GetOrCreate(key string, value time.Time) (time.Time, e
71
67
}
72
68
73
69
func (dc * directoryCache ) Purge () error {
74
- files , err := dc .basePath () .ReadDir ()
70
+ files , err := dc .baseDir .ReadDir ()
75
71
if err != nil {
76
72
return err
77
73
}
@@ -88,16 +84,15 @@ func (dc *directoryCache) removeIfExpired(dir *paths.Path) {
88
84
if lifeExpectancy > 0 {
89
85
return
90
86
}
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 ()
94
89
95
90
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 ))
97
92
}
98
93
}
99
94
100
- func newDirectoryCache (baseDir string , ttl time.Duration ) * directoryCache {
95
+ func newDirectoryCache (baseDir * paths. Path , ttl time.Duration ) * directoryCache {
101
96
return & directoryCache {
102
97
baseDir : baseDir ,
103
98
ttl : ttl ,
0 commit comments