Get config passed as cmd args instead.
This commit is contained in:
parent
33f69eaf44
commit
deed268b4f
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dwelling-upload/internal/configuration"
|
|
||||||
"dwelling-upload/pkg/logging"
|
"dwelling-upload/pkg/logging"
|
||||||
"dwelling-upload/pkg/utils"
|
"dwelling-upload/pkg/utils"
|
||||||
"flag"
|
"flag"
|
||||||
@ -14,6 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
||||||
|
var uploadDir *string = flag.String("upload-dir", "/srv/uploads", "path to a directory where uploaded files are stored")
|
||||||
|
var keepFileForHours *int64 = flag.Int64("keep-for", 36, "keep files for this much hours")
|
||||||
var showVersion *bool = flag.Bool("v", false, "show version")
|
var showVersion *bool = flag.Bool("v", false, "show version")
|
||||||
|
|
||||||
var version string
|
var version string
|
||||||
@ -33,7 +34,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer logClean.Close()
|
defer logClean.Close()
|
||||||
|
|
||||||
uploadsDir, err := ioutil.ReadDir(config.Uploads.Directory)
|
uploadsDir, err := ioutil.ReadDir(*uploadDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to open directory %s: %s\n", *uploadDir, err)
|
log.Fatalf("failed to open directory %s: %s\n", *uploadDir, err)
|
||||||
}
|
}
|
||||||
@ -42,8 +43,8 @@ func main() {
|
|||||||
var deletedSize int64 = 0
|
var deletedSize int64 = 0
|
||||||
|
|
||||||
for _, entry := range uploadsDir {
|
for _, entry := range uploadsDir {
|
||||||
if time.Now().UTC().Sub(entry.ModTime().UTC()) >= time.Duration(config.Uploads.Limits.KeepForHours)*time.Hour {
|
if time.Now().UTC().Sub(entry.ModTime().UTC()) >= time.Duration(*keepFileForHours)*time.Hour {
|
||||||
if err := os.Remove(path.Join(config.Uploads.Directory, 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 file %s: %s", entry.Name(), err)
|
||||||
} else {
|
} else {
|
||||||
deletedSize += entry.Size()
|
deletedSize += entry.Size()
|
||||||
|
Loading…
Reference in New Issue
Block a user