clean.go 426 B

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