diff options
| author | lost+skunk <[email protected]> | 2024-08-14 19:18:06 +0300 |
|---|---|---|
| committer | lost+skunk <[email protected]> | 2024-08-14 19:18:06 +0300 |
| commit | 2f8c35ba322e3c8c6e0bff8f7818d4eedf002928 (patch) | |
| tree | 3158276fa91553bc87cbb751204d832b3616bfde /app/cache.go | |
| parent | 513543cc7a24330e3d9ce96d3b55e4726397af50 (diff) | |
| download | skunky-art-2f8c35ba322e3c8c6e0bff8f7818d4eedf002928.tar.gz skunky-art-2f8c35ba322e3c8c6e0bff8f7818d4eedf002928.tar.bz2 skunky-art-2f8c35ba322e3c8c6e0bff8f7818d4eedf002928.zip | |
user favourites
Diffstat (limited to 'app/cache.go')
| -rw-r--r-- | app/cache.go | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/app/cache.go b/app/cache.go index dedba83..6506cfc 100644 --- a/app/cache.go +++ b/app/cache.go @@ -99,34 +99,36 @@ func (s skunkyart) DownloadAndSendMedia(subdomain, path string) { func InitCacheSystem() { c := &CFG.Cache - os.Mkdir(c.Path, 0700) for { - dir, e := os.Open(c.Path) - try(e) - stat, e := dir.Stat() - try(e) - - dirnames, e := dir.Readdirnames(-1) - try(e) - for _, a := range dirnames { - a = c.Path + "/" + a + dir, err := os.ReadDir(c.Path) + if err != nil { + if os.IsNotExist(err) { + os.Mkdir(c.Path, 0700) + continue + } + println(err.Error()) + } + + for _, file := range dir { + fileName := c.Path + "/" + file.Name() + fileInfo, err := file.Info() + try(err) + if c.Lifetime != "" { now := time.Now().UnixMilli() - f, _ := os.Stat(a) - stat := f.Sys().(*syscall.Stat_t) + stat := fileInfo.Sys().(*syscall.Stat_t) time := statTime(stat) if time+lifetimeParsed <= now { - try(os.RemoveAll(a)) + try(os.RemoveAll(fileName)) } } - if c.MaxSize != 0 && stat.Size() > c.MaxSize { - try(os.RemoveAll(a)) + if c.MaxSize != 0 && fileInfo.Size() > c.MaxSize { + try(os.RemoveAll(fileName)) } } - dir.Close() time.Sleep(time.Second * time.Duration(c.UpdateInterval)) } } |
