ioutil package is deprecated, so its ReadDir() was replaced by os. ReadDir() and os.Stat(). Also fixed existing error messages a little.
This commit is contained in:
parent
1c7f03053f
commit
e430f0bfc9
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -28,15 +27,21 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadsDir, err := ioutil.ReadDir(*uploadDir)
|
uploadsDir, err := os.ReadDir(*uploadDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to open directory %s: %s\n", *uploadDir, err)
|
log.Fatalf("failed to open a directory %s: %s\n", *uploadDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range uploadsDir {
|
for _, entry := range uploadsDir {
|
||||||
if time.Now().UTC().Sub(entry.ModTime().UTC()) >= time.Duration(*keepForHours)*time.Hour {
|
file, err := os.Stat(entry.Name())
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to stat a file %s: %s", entry.Name(), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if time.Now().UTC().Sub(file.ModTime().UTC()) >= time.Duration(*expiry)*time.Hour {
|
||||||
if err := os.Remove(path.Join(*uploadDir, entry.Name())); err != nil {
|
if err := os.Remove(path.Join(*uploadDir, entry.Name())); err != nil {
|
||||||
log.Printf("failed to remove file %s: %s", entry.Name(), err)
|
log.Printf("failed to remove a file %s: %s", entry.Name(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user