mirror of
https://github.com/nxshock/simplefileshare.git
synced 2025-07-02 00:13:36 +05:00
Import project
This commit is contained in:
parent
f0e39831c2
commit
1b0cbbf5cd
13 changed files with 588 additions and 0 deletions
44
walker.go
Normal file
44
walker.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func removeOldFilesThread(path string, olderThan time.Duration) {
|
||||
ticker := time.NewTicker(olderThan)
|
||||
|
||||
for _ = range ticker.C {
|
||||
log.Debugln("Removing old files...")
|
||||
err := removeOldFiles(path, olderThan)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Debugln("Removing old files completed.")
|
||||
}
|
||||
}
|
||||
|
||||
func removeOldFiles(path string, olderThan time.Duration) error {
|
||||
return filepath.Walk(config.StoragePath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if info.ModTime().Add(olderThan).Before(time.Now()) {
|
||||
log.WithField("filepath", path).Debugln("Removing file...")
|
||||
err := os.Remove(path)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue