-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
53 lines (47 loc) · 893 Bytes
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package simplemon
import (
"errors"
"fmt"
"os"
"path/filepath"
"time"
)
func ageDaysOfNewestFile(glob string) (time.Duration, error) {
files, err := filepath.Glob(glob)
if err != nil {
return 0, err
}
if len(files) == 0 {
return 0, fmt.Errorf("no files found at %s", glob)
}
var newest time.Time
for _, f := range files {
info, err := os.Stat(f)
if err != nil {
return 0, err
}
if info.ModTime().After(newest) {
newest = info.ModTime()
}
}
return time.Since(newest), nil
}
func allDirsUnder(root string) (dirs []string) {
err := filepath.Walk(root, func(path string, info os.FileInfo, e error) error {
if e != nil && errors.Is(e, os.ErrNotExist) {
return nil
}
if e != nil {
fmt.Println(e)
return e
}
if info.IsDir() {
dirs = append(dirs, path)
}
return nil
})
if err != nil {
fmt.Println("outer:", err)
}
return dirs
}