mirrored from https://skia.googlesource.com/buildbot
-
Notifications
You must be signed in to change notification settings - Fork 65
/
radix_dir.go
48 lines (38 loc) · 967 Bytes
/
radix_dir.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
package main
import (
"io/ioutil"
"os"
"path/filepath"
"go.skia.org/infra/go/common"
"go.skia.org/infra/go/fileutil"
"go.skia.org/infra/go/sklog"
)
func main() {
common.Init()
fileInfos, err := ioutil.ReadDir(".")
if err != nil {
sklog.Fatalf("Unable to read directory.")
}
// Get the directory
for _, info := range fileInfos {
if info.IsDir() {
continue
}
fileName := info.Name()
outFileName := fileutil.TwoLevelRadixPath(fileName)
if fileName == outFileName {
sklog.Infof("Excluding %s -> %s", fileName, outFileName)
continue
}
if !fileutil.FileExists(outFileName) {
// Create the path if it doesn't exist.
targetDir, _ := filepath.Split(outFileName)
if err = os.MkdirAll(targetDir, 0700); err != nil {
sklog.Errorf("Unable to run create path: %s", targetDir)
}
if err := os.Rename(fileName, outFileName); err != nil {
sklog.Errorf("Unable to run mv %s %s", fileName, outFileName)
}
}
}
}