Revisions
-
chressie revised this gist
Jul 15, 2010 . 1 changed file with 18 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,23 +8,34 @@ import ( ) type V struct { list vector.StringVector visited map[uint64]bool } func (v *V) VisitDir(path string, f *os.FileInfo) bool { if _, ok := v.visited[f.Ino]; !ok { v.visited[f.Ino] = true return true } return false } func (v *V) VisitFile(p string, f *os.FileInfo) { if f.Name == "PKGBUILD" { v.list.Push(p[0 : len(p)-8]) // remove PKGBUILD from path and store it in vector return } if g, err := os.Stat(p); err == nil && g.IsDirectory() { d, _ := path.Split(p) l, _ := os.Readlink(p) path.Walk(path.Join(d, l), v, nil) } } func main() { v := new(V) v.visited = make(map[uint64]bool) path.Walk("tmp", v, nil) for _, s := range v.list { fmt.Println(s) } -
chressie created this gist
Jul 15, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ package main import ( "container/vector" "fmt" "os" "path" ) type V struct { list vector.StringVector } func (*V) VisitDir(path string, f *os.FileInfo) bool { // walk in each directory return true } func (v *V) VisitFile(path string, f *os.FileInfo) { if f.Name == "PKGBUILD" { v.list.Push(path[0:len(path)-8]) // remove PKGBUILD from path and store it in vector } } func main() { v := new(V) path.Walk("/tmp", v, nil) for _, s := range v.list { fmt.Println(s) } }