From d919d00cc0023b4d1073afe718d54c81370a7bc2 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 5 Aug 2023 19:28:05 +0400 Subject: [PATCH] In dwelling-upload-clean converted an expiry var to time.Duration. Added an 'h' unit in a .service to represent hours. --- cmd/dwelling-upload-clean/main.go | 6 +++--- init/systemd/dwelling-upload-clean.service | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/dwelling-upload-clean/main.go b/cmd/dwelling-upload-clean/main.go index 8c9751a..ad0f89f 100644 --- a/cmd/dwelling-upload-clean/main.go +++ b/cmd/dwelling-upload-clean/main.go @@ -10,8 +10,8 @@ import ( ) var ( - uploadDir *string = flag.String("dir", "/srv/upload", "path to a directory where uploaded files are stored") - expiry *int64 = flag.Int64("expiry", 36, "keep files for this much hours") + uploadDir *string = flag.String("dir", "/srv/upload", "path to a directory where uploaded files are stored") + expiry *time.Duration = flag.Duration("expiry", 36*time.Hour, "keep files for this much hours") showVersion *bool = flag.Bool("v", false, "show version") ) @@ -39,7 +39,7 @@ func main() { continue } - if time.Now().UTC().Sub(file.ModTime().UTC()) >= time.Duration(*expiry)*time.Hour { + if time.Now().UTC().Sub(file.ModTime().UTC()) >= *expiry { if err := os.Remove(path.Join(*uploadDir, entry.Name())); err != nil { log.Printf("failed to remove a file %s: %s", entry.Name(), err) } diff --git a/init/systemd/dwelling-upload-clean.service b/init/systemd/dwelling-upload-clean.service index a99cbf6..0da2e53 100755 --- a/init/systemd/dwelling-upload-clean.service +++ b/init/systemd/dwelling-upload-clean.service @@ -5,7 +5,7 @@ Description=dwelling-upload-clean Type=oneshot User=dwupload Group=dwupload -ExecStart=/usr/bin/dwelling-upload-clean -dir /srv/upload -expiry 36 +ExecStart=/usr/bin/dwelling-upload-clean -dir /srv/upload -expiry 36h ReadOnlyPaths=/ # Set here path to directory where uploads are stored.