clean.go 455 B

1234567891011121314151617181920212223242526
  1. package session
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "strings"
  6. "time"
  7. )
  8. func Clean(tmpdir string) error {
  9. files, err := ioutil.ReadDir(tmpdir)
  10. if err != nil {
  11. return err
  12. }
  13. for _, file := range files {
  14. if len(file.Name()) == 40 {
  15. if diff := time.Since(file.ModTime()); diff > 24*time.Hour {
  16. err = os.Remove(strings.Join([]string{tmpdir, file.Name()}, string(os.PathSeparator)))
  17. if err != nil {
  18. return err
  19. }
  20. }
  21. }
  22. }
  23. return nil
  24. }