-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilehelpers.go
More file actions
56 lines (51 loc) · 1.21 KB
/
filehelpers.go
File metadata and controls
56 lines (51 loc) · 1.21 KB
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
54
55
56
package main
import (
"os"
"path/filepath"
"time"
)
// getFiles recursively walks dir tree and returns all files inside (absolute
// paths)
func getFiles(dir string) ([]string, error) {
var files []string
err := filepath.Walk(dir, func(fp string, info os.FileInfo, err error) error {
if !info.IsDir() {
abs, err := filepath.Abs(fp)
if err == nil {
files = append(files, abs)
}
}
return nil
})
return files, err
}
// filterFiles takes a slice of files and function to evaluate each file with
func filterFiles(slice []string, condition func(string) bool) []string {
var newSlice []string
for _, element := range slice {
if condition(element) {
newSlice = append(newSlice, element)
}
}
return newSlice
}
// statMtime returns file mtime (when content of the file were last modified)
func statMtime(fp string) (time.Time, error) {
file, err := os.Stat(fp)
if err != nil {
return time.Time{}, err
}
return file.ModTime(), nil
}
// mkSetStr returns slice containing only unique items
func mkSetStr(slice []string) []string {
tmpList := make(map[string]bool)
for _, el := range slice {
tmpList[el] = true
}
slice = nil
for el := range tmpList {
slice = append(slice, el)
}
return slice
}