linx-server/expiry.go

41 lines
658 B
Go
Raw Normal View History

2015-09-28 04:17:12 +02:00
package main
import (
"time"
)
// Get what the unix timestamp will be in "seconds".
2015-09-30 01:00:16 +02:00
func getFutureTimestamp(seconds int64) (ts int64) {
now := int64(time.Now().Unix())
2015-09-28 04:17:12 +02:00
if seconds == 0 {
ts = 0
} else {
ts = now + seconds
}
return
}
// Determine if a file with expiry set to "ts" has expired yet
2015-09-30 01:00:16 +02:00
func isTsExpired(ts int64) (expired bool) {
now := int64(time.Now().Unix())
2015-09-28 04:17:12 +02:00
if ts == 0 {
expired = false
} else if now > ts {
expired = true
} else {
expired = false
}
return
}
// Determine if the given filename is expired
func isFileExpired(filename string) bool {
exp, _ := metadataGetExpiry(filename)
2015-09-28 04:17:12 +02:00
return isTsExpired(exp)
2015-09-28 04:17:12 +02:00
}