Skip to content

Commit 596a373

Browse files
BennyThinkn0vad3v
andauthored
patch for undeleted tmp (#403)
* patch for undeleted tmp * every 30s * bump version --------- Co-authored-by: n0vad3v <n0vad3v@riseup.net>
1 parent 6dbc328 commit 596a373

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ coverage.txt
2626
.DS_Store
2727
/webp_server_go
2828
/metadata/*
29+
/.idea/inspectionProfiles/Project_Default.xml

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
PrefetchForeground bool // Standalone prefetch, prefetch and exit
5656
AllowNonImage bool
5757
Config = NewWebPConfig()
58-
Version = "0.13.6"
58+
Version = "0.13.7"
5959
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
6060
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
6161
LocalHostAlias = "local"

schedule/cache_clean.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,27 @@ func CleanCache() {
113113
}
114114
}
115115
}
116+
117+
func DeleteDeadCache() {
118+
ticker := time.NewTicker(30 * time.Second)
119+
defer ticker.Stop()
120+
threshold := time.Now().Add(-10 * time.Minute)
121+
for {
122+
select {
123+
case <-ticker.C:
124+
_ = filepath.Walk(os.TempDir()+"vips-", func(path string, info os.FileInfo, err error) error {
125+
log.Debugf("Checking possible dead cache: %s", path)
126+
if err != nil {
127+
return err
128+
}
129+
if info.IsDir() && info.ModTime().Before(threshold) {
130+
// only delete directory
131+
log.Warnf("Deleting: %s", path)
132+
_ = os.RemoveAll(path)
133+
return filepath.SkipDir
134+
}
135+
return nil
136+
})
137+
}
138+
}
139+
}

webp-server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func init() {
9898
}
9999

100100
func main() {
101+
go schedule.DeleteDeadCache()
101102
if config.Config.MaxCacheSize != 0 {
102103
go schedule.CleanCache()
103104
}

0 commit comments

Comments
 (0)