func createIndex(args ...string) { dirs_to_index := preparePaths(args) ix := index.Create(*indexFilename) ix.Verbose = *verboseFlag ix.AddPaths(dirs_to_index) for _, arg := range dirs_to_index { log.Printf("index %s", arg) filepath.Walk(arg, func(path string, info os.FileInfo, err error) error { if _, elem := filepath.Split(path); elem != "" { // Skip various temporary or "hidden" files or directories. if elem[0] == '.' || elem[0] == '#' || elem[0] == '~' || elem[len(elem)-1] == '~' { if info.IsDir() { return filepath.SkipDir } return nil } } if err != nil { log.Printf("%s: %s", path, err) return nil } if info != nil && info.Mode()&os.ModeType == 0 { ix.AddFile(path) } return nil }) } log.Printf("flush index") ix.Flush() ix.Close() log.Printf("done") return }
func reindex(paths []string, curdir string) { paths = preparePaths(paths) log.Printf("Reindexing %v\n", paths) master := *indexFilename log.Println("Master is ", master) file := master + "~" ix := index.Create(file) defer cleanupFile(file) //ix.AddPaths([]string{curdir}) //ix.AddPaths([]string{"c:\\Users\\rich\\workspace\\sitm"}) added_files := false for _, p := range paths { if _, elem := filepath.Split(p); elem != "" { // Skip various temporary or "hidden" files or directories. if elem[0] == '.' || elem[0] == '#' || elem[0] == '~' || elem[len(elem)-1] == '~' { log.Println("reindex skipping " + p) continue } if _, err := os.Stat(p); err != nil { log.Println("reindex skipping (err stat'ing )" + p) continue } } log.Println("AddFile ", p) ix.AddPaths([]string{p}) ix.AddFile(p) added_files = true } ix.Flush() ix.Close() if !added_files { return } index.Merge(file+"~", master, file) defer cleanupFile(file + "~") _, err := copyFile(master, file+"~") if err != nil { panic("copy: " + err.Error()) } log.Println("Updated file " + master) }