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:
parent
1e30e5e8ff
commit
d919d00cc0
@ -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)
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user