Exemple #1
0
/*
 readFiles reads all files with the .go extension and creates their AST.
 It also creates a list of local imports (everything starting with ./)
 and searches the main package files for the main function.
*/
func readFiles(rootpath string) {
	var realpath, symname string
	// path walker error channel
	errorChannel := make(chan os.Error, 64)

	// check if this is a symlink
	if dir, err := os.Stat(rootpath); err == nil {
		if dir.FollowedSymlink {
			realpath, _ = os.Readlink(rootpath)
			if realpath[0] != '/' {
				realpath = rootpath[0:strings.LastIndex(rootpath, "/")+1] + realpath
			}
			symname = rootpath[len(rootPath)+1:]
		} else {
			realpath = rootpath
		}
	} else {
		logger.Warn("%s\n", err)
	}

	// visitor for the path walker
	visitor := &goFileVisitor{rootpath, realpath, symname}

	path.Walk(visitor.realpath, visitor, errorChannel)

	if err, ok := <-errorChannel; ok {
		logger.Error("Error while traversing directories: %s\n", err)
	}
}
Exemple #2
0
func walkargs(args []string, paths chan<- string) {
	defer close(paths)
	errors := make(chan os.Error)
	defer close(errors)
	var manager Manager
	walker := Walker{paths: paths, visited: make(map[string]bool)}
	for _, arg := range args {
		manager.Go(func(root string) func() {
			return func() {
				fmt.Println(root)
				path.Walk(root, walker, errors)
			}
		}(arg))
	}
	go func() {
		for {
			err := <-errors
			if closed(errors) {
				return
			}
			fmt.Println(err)
		}
	}()
	manager.Wait()
}
Exemple #3
0
func main() {
	for _, dir := range flag.Args() {
		fmt.Printf("dir: %s\n", dir)
		errChan := errChan()
		path.Walk(dir, Visitor(errChan), errChan)
	}
}
Exemple #4
0
func Serve(c net.Conn) {
	defer c.Close()
	var p string
	n, err := fmt.Fscanln(c, &p)
	if n != 1 || err != nil {
		fmt.Fprint(c, Error("invalid request"))
		return
	}
	filename := *root + path.Clean("/"+p)
	fi, err := os.Stat(filename)
	if err != nil {
		fmt.Fprint(c, Error("not found"))
		return
	}
	if fi.IsDirectory() {
		var list Listing
		path.Walk(filename, &list, nil)
		fmt.Fprint(c, list)
		return
	}
	f, err := os.Open(filename, os.O_RDONLY, 0)
	if err != nil {
		fmt.Fprint(c, Error("couldn't open file"))
		return
	}
	io.Copy(c, f)
}
Exemple #5
0
func walkDir(path string) {
	// start an error handler
	v := make(fileVisitor)
	go func() {
		for err := range v {
			if err != nil {
				report(err)
			}
		}
	}()
	// walk the tree
	pathutil.Walk(path, v, v)
	close(v)
}
Exemple #6
0
func walkDir(path string) {
	// start an error handler
	done := make(chan bool)
	v := make(fileVisitor)
	go func() {
		for err := range v {
			if err != nil {
				report(err)
			}
		}
		done <- true
	}()
	// walk the tree
	pathutil.Walk(path, v, v)
	close(v) // terminate error handler loop
	<-done   // wait for all errors to be reported
}
Exemple #7
0
// NewIndex creates a new index for the file tree rooted at root.
func NewIndex(root string) *Index {
	var x Indexer

	// initialize Indexer
	x.words = make(map[string]*IndexResult)

	// collect all Spots
	pathutil.Walk(root, &x, nil)

	// for each word, reduce the RunLists into a LookupResult;
	// also collect the word with its canonical spelling in a
	// word list for later computation of alternative spellings
	words := make(map[string]*LookupResult)
	var wlist RunList
	for w, h := range x.words {
		decls := reduce(&h.Decls)
		others := reduce(&h.Others)
		words[w] = &LookupResult{
			Decls:  decls,
			Others: others,
		}
		wlist.Push(&wordPair{canonical(w), w})
	}

	// reduce the word list {canonical(w), w} into
	// a list of AltWords runs {canonical(w), {w}}
	alist := wlist.reduce(lessWordPair, newAltWords)

	// convert alist into a map of alternative spellings
	alts := make(map[string]*AltWords)
	for i := 0; i < alist.Len(); i++ {
		a := alist.At(i).(*AltWords)
		alts[a.Canon] = a
	}

	// convert snippet vector into a list
	snippets := make([]*Snippet, x.snippets.Len())
	for i := 0; i < x.snippets.Len(); i++ {
		snippets[i] = x.snippets.At(i).(*Snippet)
	}

	return &Index{words, alts, snippets, x.nspots}
}
Exemple #8
0
func main() {
	// parse and handle options
	opts.Parse()
	if *showVersion {
		ShowVersion()
		os.Exit(0)
	}
	// if there are no files, generate a list
	if len(opts.Args) == 0 {
		path.Walk(".", GoFileFinder{}, nil)
	} else {
		for _, fname := range opts.Args {
			files.Push(fname)
		}
	}
	GetPackageList()
	PrintAutoNotice()
	PrintFList()
	PrintPList()
	fmt.Println("GOPACKAGES = ${GOPKGS:=.${O}}")
	fmt.Println("GOARCHIVES = ${GOPKGS:=.a}")
}
Exemple #9
0
func main() {
	opts.Usage = "[file1.go [...]]"
	opts.Description =
		`construct and print a dependency tree for the given source files.`
		// parse and handle options
	opts.Parse()
	if *showVersion {
		ShowVersion()
		os.Exit(0)
	}
	// if there are no files, generate a list
	if len(opts.Args) == 0 {
		path.Walk(".", GoFileFinder{}, nil)
	} else {
		for _, fname := range opts.Args {
			files.Push(fname)
		}
	}
	// for each file, list dependencies
	for _, fname := range files {
		file, err := parser.ParseFile(fname, nil, parser.ImportsOnly)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", err)
			os.Exit(1)
		}
		HandleFile(fname, file)
	}
	PrintAutoNotice()
	FindMain()
	if *showNeeded {
		PrintNeeded(".EXTERNAL: ", ".a")
	}
	// in any case, print as a comment
	PrintNeeded("# external packages: ", "")
	PrintDeps()
}
Exemple #10
0
func main() {
	flag.Parse()
	fmt.Printf(headerString())
	// Flag Testing
	if *announceUrl == "" {
		fmt.Fprintf(os.Stderr, "Must supply an Announce URL parameter (-a).\n")
		os.Exit(1)
	}

	if *torrentFilename == "" {
		fmt.Fprintf(os.Stderr, "Must supply a torrent file name to produce.\n")
		os.Exit(1)
	}

	v, resC := newVisitor()
	errC := make(chan os.Error)
	go func() {
		err := <-errC
		panic(err)
	}()

	// Try to open the torrent file. If this fails, it ensures we fail long before the
	// hashing commences.
	f, err := os.Open(*torrentFilename, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0660)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	args := flag.Args()
	for i := range args {
		path.Walk(args[i], v, errC)
	}

	writeTorrent(v, f, resC)
}
Exemple #11
0
func findPackages(dir string) []string {
	v := new(packagesVisitor)
	path.Walk(dir, v, nil)
	return v.packages
}
Exemple #12
0
func findPackageDirs() []string {
	srcPkg := path.Join(GOROOT, "src", "pkg")
	v := new(pkgDirsVisitor)
	path.Walk(srcPkg, v, nil)
	return v.pkgDirs
}
Exemple #13
0
func walkDir(dirname string, v path.Visitor) {
	// first make sure the directory exists
	readDir(dirname)
	// now walk it
	path.Walk(dirname, v, nil)
}
Exemple #14
0
func (self *fileList) ToSlice() []string {
	path.Walk(self.basePath, self, self.Errors)
	return self.filenames.Copy()
}
Exemple #15
0
func (this *TempDir) AllFiles() []string {
	collector := CollectFilesInDir(this.path)
	path.Walk(this.path, collector, nil)
	return collector.Files()
}
Exemple #16
0
func main() {
	v := &SimpleVisitor{}
	errors := make(chan os.Error)
	path.Walk("/etc/httpd", v, errors)
}