Snake case to camel case. Fixed argument parsing. Added a statistics log line to tell how much files gets deleted.
This commit is contained in:
parent
10a64306a3
commit
9b5ae547cc
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"dwelling-upload/internal/configuration"
|
||||
"dwelling-upload/pkg/utils"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -10,32 +11,36 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var configPath string = *flag.String("conf", "config.yaml", "path to configuration file")
|
||||
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
||||
|
||||
func main() {
|
||||
config, err := configuration.LoadConfiguration(configPath)
|
||||
flag.Parse()
|
||||
|
||||
config, err := configuration.LoadConfiguration(*configPath)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
_ = config
|
||||
|
||||
uploads_dir, err := ioutil.ReadDir(config.Uploads.Directory)
|
||||
uploadsDir, err := ioutil.ReadDir(config.Uploads.Directory)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open directory %s: %s\n", config.Uploads.Directory, err)
|
||||
}
|
||||
|
||||
var deleted_count int64 = 0
|
||||
var deteted_size int64 = 0
|
||||
var deletedCount int64 = 0
|
||||
var deletedSize int64 = 0
|
||||
|
||||
for _, entry := range uploads_dir {
|
||||
for _, entry := range uploadsDir {
|
||||
if time.Duration(entry.ModTime().UTC().Sub(time.Now().UTC()).Hours()) >= time.Duration(config.Uploads.Limits.KeepForHours)*time.Hour {
|
||||
if err := os.Remove(path.Join(config.Uploads.Directory, entry.Name())); err != nil {
|
||||
log.Fatalln("failed to remove file ", entry.Name(), ": ", err)
|
||||
}
|
||||
deteted_size += entry.Size()
|
||||
deleted_count++
|
||||
deletedSize += entry.Size()
|
||||
deletedCount++
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(deleted_count, " file(s) in total of ", deteted_size/1024/1024, " MiB was removed during this run.")
|
||||
_, _, cFSz := utils.ConvertFileSize(deletedSize)
|
||||
|
||||
log.Println(deletedCount, "file(s) in total of", cFSz, "was removed during this run.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user