From 0005191d7100697550bc57706f1bb911b8d650ff Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 21 Jun 2015 17:32:40 +0200 Subject: [PATCH] Remove `dirdiff` and `gentestdata` --- cmd/dirdiff/main.go | 142 ---------------------------------------- cmd/gentestdata/main.go | 69 ------------------- 2 files changed, 211 deletions(-) delete mode 100644 cmd/dirdiff/main.go delete mode 100644 cmd/gentestdata/main.go diff --git a/cmd/dirdiff/main.go b/cmd/dirdiff/main.go deleted file mode 100644 index 23182f5bf..000000000 --- a/cmd/dirdiff/main.go +++ /dev/null @@ -1,142 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - "syscall" -) - -type entry struct { - path string - fi os.FileInfo -} - -func walk(dir string) <-chan *entry { - ch := make(chan *entry, 100) - - go func() { - err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - return nil - } - - name, err := filepath.Rel(dir, path) - if err != nil { - fmt.Fprintf(os.Stderr, "error: %v\n", err) - return nil - } - - ch <- &entry{ - path: name, - fi: info, - } - - return nil - }) - - if err != nil { - fmt.Fprintf(os.Stderr, "Walk() error: %v\n", err) - } - - close(ch) - }() - - // first element is root - _ = <-ch - - return ch -} - -func (e *entry) equals(other *entry) bool { - if e.path != other.path { - fmt.Printf("path does not match\n") - return false - } - - if e.fi.Mode() != other.fi.Mode() { - fmt.Printf("mode does not match\n") - return false - } - - if e.fi.ModTime() != other.fi.ModTime() { - fmt.Printf("%s: ModTime does not match\n", e.path) - // TODO: Fix ModTime for symlinks, return false - // see http://grokbase.com/t/gg/golang-nuts/154wnph4y8/go-nuts-no-way-to-utimes-a-symlink - return true - } - - stat, _ := e.fi.Sys().(*syscall.Stat_t) - stat2, _ := other.fi.Sys().(*syscall.Stat_t) - - if stat.Uid != stat2.Uid || stat2.Gid != stat2.Gid { - return false - } - - return true -} - -func main() { - if len(os.Args) != 3 { - fmt.Fprintf(os.Stderr, "USAGE: %s DIR1 DIR2\n", os.Args[0]) - os.Exit(1) - } - - ch1 := walk(os.Args[1]) - ch2 := walk(os.Args[2]) - - changes := false - - var a, b *entry - for { - var ok bool - - if ch1 != nil && a == nil { - a, ok = <-ch1 - if !ok { - ch1 = nil - } - } - - if ch2 != nil && b == nil { - b, ok = <-ch2 - if !ok { - ch2 = nil - } - } - - if ch1 == nil && ch2 == nil { - break - } - - if ch1 == nil { - fmt.Printf("+%v\n", b.path) - changes = true - } else if ch2 == nil { - fmt.Printf("-%v\n", a.path) - changes = true - } else if !a.equals(b) { - if a.path < b.path { - fmt.Printf("-%v\n", a.path) - changes = true - a = nil - continue - } else if a.path > b.path { - fmt.Printf("+%v\n", b.path) - changes = true - b = nil - continue - } else { - fmt.Printf("%%%v\n", a.path) - changes = true - } - } - - a, b = nil, nil - } - - if changes { - os.Exit(1) - } -} diff --git a/cmd/gentestdata/main.go b/cmd/gentestdata/main.go deleted file mode 100644 index c4b3604b3..000000000 --- a/cmd/gentestdata/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "fmt" - "io" - "math/rand" - "os" - "path/filepath" -) - -const ( - MaxFiles = 23 - MaxDepth = 3 -) - -var urnd *os.File - -func init() { - f, err := os.Open("/dev/urandom") - if err != nil { - panic(err) - } - - urnd = f -} - -func rndRd(bytes int) io.Reader { - return io.LimitReader(urnd, int64(bytes)) -} - -func createDir(target string, depth int) { - fmt.Printf("createDir %s, depth %d\n", target, depth) - err := os.Mkdir(target, 0755) - if err != nil && !os.IsExist(err) { - panic(err) - } - - for i := 0; i < MaxFiles; i++ { - if depth == 0 { - filename := filepath.Join(target, fmt.Sprintf("file%d", i)) - fmt.Printf("create file %v\n", filename) - f, err := os.Create(filename) - if err != nil { - panic(err) - } - - _, err = io.Copy(f, rndRd(rand.Intn(1024))) - if err != nil { - panic(err) - } - - err = f.Close() - if err != nil { - panic(err) - } - } else { - createDir(filepath.Join(target, fmt.Sprintf("dir%d", i)), depth-1) - } - } -} - -func main() { - if len(os.Args) != 2 { - fmt.Fprintf(os.Stderr, "USAGE: %s TARGETDIR\n", os.Args[0]) - os.Exit(1) - } - - createDir(os.Args[1], MaxDepth) -}