1
0

In dwelling-upload-clean converted an expiry var to time.Duration. Added an 'h' unit in a .service to represent hours.

This commit is contained in:
Alexander Andreev 2023-08-05 19:28:05 +04:00
parent 1e30e5e8ff
commit d919d00cc0
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 4 additions and 4 deletions

View File

@ -10,8 +10,8 @@ import (
) )
var ( var (
uploadDir *string = flag.String("dir", "/srv/upload", "path to a directory where uploaded files are stored") 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") expiry *time.Duration = flag.Duration("expiry", 36*time.Hour, "keep files for this much hours")
showVersion *bool = flag.Bool("v", false, "show version") showVersion *bool = flag.Bool("v", false, "show version")
) )
@ -39,7 +39,7 @@ func main() {
continue 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 { if err := os.Remove(path.Join(*uploadDir, entry.Name())); err != nil {
log.Printf("failed to remove a file %s: %s", entry.Name(), err) log.Printf("failed to remove a file %s: %s", entry.Name(), err)
} }

View File

@ -5,7 +5,7 @@ Description=dwelling-upload-clean
Type=oneshot Type=oneshot
User=dwupload User=dwupload
Group=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=/ ReadOnlyPaths=/
# Set here path to directory where uploads are stored. # Set here path to directory where uploads are stored.