Skip to content

Commit

Permalink
Use filepath.WalkDir when evicting grid images
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Mar 15, 2024
1 parent d0611ee commit 406cb51
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
data "instafix/handlers/data"
"instafix/utils"
"instafix/views"
"io/fs"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -125,20 +126,24 @@ func main() {
// Remove file in static folder until below threshold
func evictStatic(threshold int64) {
var dirSize int64 = 0
readSize := func(path string, file os.FileInfo, err error) error {
readSize := func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !file.IsDir() {
if !d.IsDir() {
if dirSize > threshold {
err := os.Remove(path)
return err
}
dirSize += file.Size()
info, err := d.Info()
if err != nil {
return err
}
dirSize += info.Size()
}
return nil
}
filepath.Walk("static", readSize)
filepath.WalkDir("static", readSize)
}

// Remove cache from Pebble if already expired
Expand Down

0 comments on commit 406cb51

Please sign in to comment.