Exemple #1
0
func main() {
	f, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}

	des, err := dir.Readdir(f, 0)
	if err != nil {
		log.Fatal(err)
	}

	for _, de := range des {
		fmt.Println(dir.Types[de.Type], de.Ino, de.Name)
	}
}
Exemple #2
0
func countdir(js *jspec, c chan *jspec) int {
	// get entries from js.path
	f, err := os.Open(js.path)
	if err != nil {
		if *fuzzy && relaxerrno(err, syscall.ENOENT) {
			fmt.Fprintln(os.Stderr, "[W]", js.path, "got error with", err)
			return 0
		} else {
			log.Fatal(js.path, ": ", err)
		}
	}
	des, err := dir.Readdir(f, *hint)
	f.Close()
	if err != nil {
		if *fuzzy && relaxerrno(err, syscall.ENOENT, syscall.ENOTDIR) {
			fmt.Fprintln(os.Stderr, "[W]", js.path, "got error with", err)
			return 0
		} else {
			log.Fatal(js.path, ": ", err)
		}
	}

	// process the entries
	fc := 0
	for _, de := range des {
		if de.Type == dir.DT_UNKNOWN && *stat {
			de.Type, err = dir.Modestat(js.join(de).path)
			if err != nil {
				if *fuzzy && relaxerrno(err, syscall.ENOENT) {
					fmt.Fprintln(os.Stderr, "[W]", js.join(de).path,
						"got error with", err)
					continue
				} else {
					log.Fatal(js.join(de).path, ": ", err)
				}
			}
		}
		if *dump {
			var idx int
			if *dump_fullpath {
				idx = 0
			} else {
				idx = js.prefix
			}
			fmt.Printf("%d %d %s %s%c", js.runid, de.Ino, dir.Types[de.Type],
				js.join(de).path[idx:], dump_sep)
		}
		switch de.Type {
		case dir.DT_UNKNOWN:
			if !*dump {
				log.Fatal("got no filetype info: ", js.join(de).path)
			}
		case dir.DT_REG:
			if *filter != "" && *filterfiles && js.join(de).match(*filter) {
				continue
			}
			// count
			fc += 1
		case dir.DT_DIR:
			jsn := js.join(de)
			if *filter != "" && jsn.match(*filter) {
				continue
			}
			// job request sent back to scheduler
			c <- jsn
		}
	}

	if *debug {
		fmt.Println(js.path, fc)
	}

	return fc
}