Skip to content

Instantly share code, notes, and snippets.

@mrosset
Created July 15, 2010 11:20
Show Gist options
  • Save mrosset/476831 to your computer and use it in GitHub Desktop.
Save mrosset/476831 to your computer and use it in GitHub Desktop.
package main
import (
"container/vector"
"os"
"path"
"io/ioutil"
)
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(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 // prune
}
//If path is a symlink test read its contents for more paths to walk
if f.IsSymlink() && !f.FollowedSymlink { //FIME: test if FollowedSymlink is sane
dirs, _ := ioutil.ReadDir(p)
if len(dirs) > 0 {
for _, e := range dirs {
path.Walk(path.Join(p, e.Name), v, nil)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment