Skip to content

Instantly share code, notes, and snippets.

@mrosset
Forked from chressie/gist:476610
Created July 15, 2010 15:09

Revisions

  1. @chressie chressie revised this gist Jul 15, 2010. 1 changed file with 18 additions and 7 deletions.
    25 changes: 18 additions & 7 deletions gistfile1.go
    Original file line number Diff line number Diff line change
    @@ -8,23 +8,34 @@ import (
    )

    type V struct {
    list vector.StringVector
    list vector.StringVector
    visited map[uint64]bool
    }

    func (*V) VisitDir(path string, f *os.FileInfo) bool {
    // walk in each directory
    return true
    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(path string, f *os.FileInfo) {
    func (v *V) VisitFile(p 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
    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)
    path.Walk("/tmp", v, nil)
    v.visited = make(map[uint64]bool)
    path.Walk("tmp", v, nil)
    for _, s := range v.list {
    fmt.Println(s)
    }
  2. @chressie chressie created this gist Jul 15, 2010.
    31 changes: 31 additions & 0 deletions gistfile1.go
    Original 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)
    }
    }