2017-08-27 09:59:22 -04:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2024-06-30 23:14:48 -04:00
|
|
|
"time"
|
2017-08-27 09:59:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Check if a file exists and is readable etc
|
|
|
|
// returns false if not
|
|
|
|
func CheckFileExists(fpath string) bool {
|
|
|
|
_, e := os.Stat(fpath)
|
|
|
|
return e == nil
|
|
|
|
}
|
2024-06-30 23:14:48 -04:00
|
|
|
|
|
|
|
// Check if a file is more than maxAge minutes old
|
|
|
|
// returns false if
|
|
|
|
func CheckFileAge(fpath string, maxAge int) bool {
|
|
|
|
info, err := os.Stat(fpath)
|
|
|
|
if err != nil {
|
|
|
|
// file does not exist, return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
xMinAgo := time.Now().Add(time.Duration(-maxAge) * time.Minute)
|
|
|
|
// Exists and is older than age, return true
|
|
|
|
return info.ModTime().Before(xMinAgo)
|
|
|
|
}
|