-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.go
63 lines (52 loc) · 1.16 KB
/
utils.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
54
55
56
57
58
59
60
61
62
63
package main
import (
"io"
"os"
"path/filepath"
"strings"
log "github.com/sirupsen/logrus"
)
// Move file instead of renaming as renaming does not work across devices
// This is necessary as the temporary directory we use for packaging
// may be on a different disk.
func MoveFile(sourcePath, destPath string) error {
// Open input file
inputFile, err := os.Open(sourcePath)
if inputFile != nil {
defer inputFile.Close()
}
if err != nil {
return err
}
// Open output file
outputFile, err := os.Create(destPath)
if outputFile != nil {
defer outputFile.Close()
}
if err != nil {
return err
}
// Copy file
_, err = io.Copy(outputFile, inputFile)
return err
}
func deleteFilesWithoutGoExtension(root string) error {
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Skip directories
if info.IsDir() {
return nil
}
// Check if the file has a ".go" extension
if !strings.HasSuffix(info.Name(), ".go") {
log.Debug("deleteFilesWithoutGoExtension: Deleting: " + path)
if err := os.Remove(path); err != nil {
return err
}
}
return nil
})
return err
}