Move the logic outside and use scripting, cronjob to delete files. Fixes #1019master
parent
15924a8f05
commit
454d71cafa
@ -1,41 +0,0 @@ |
||||
package fs |
||||
|
||||
import ( |
||||
"os" |
||||
"time" |
||||
) |
||||
|
||||
// AutoExpiryThread - auto expiry thread
|
||||
func (fs Filesystem) AutoExpiryThread(expiry time.Duration) { |
||||
expireFiles := func(fp string, fl os.FileInfo, err error) error { |
||||
if fp == fs.path { |
||||
return nil |
||||
} |
||||
if fl.Mode().IsRegular() || fl.Mode()&os.ModeSymlink == os.ModeSymlink { |
||||
if time.Now().Sub(fl.ModTime()) > expiry { |
||||
if err := os.Remove(fp); err != nil { |
||||
if os.IsNotExist(err) { |
||||
return nil |
||||
} |
||||
return err |
||||
} |
||||
} |
||||
return ErrDirNotEmpty |
||||
} |
||||
return nil |
||||
} |
||||
ticker := time.NewTicker(3 * time.Hour) |
||||
for { |
||||
select { |
||||
// TODO - add a way to stop the timer thread
|
||||
case <-ticker.C: |
||||
err := WalkUnsorted(fs.path, expireFiles) |
||||
if err != nil { |
||||
if !os.IsNotExist(err) && err != ErrDirNotEmpty { |
||||
ticker.Stop() |
||||
return |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue