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
@ -11,7 +11,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user