Ejemplo n.º 1
0
// Build index, starts when app start...
func Build_index(path string) {

	if dirlist == nil {
		dirlist = fuzzyfs.NewDirList()
		dirlist.MaxDepth = depth
		dirlist.PathSelect = fuzzyfs.DirsAndSymlinksAsDirs
	}

	startTime := time.Now()
	log.Printf("Building index .. %s, depth: %d", path, depth)
	err := dirlist.Populate(path, nil)
	if err != nil {
		panic(err)
	}
	endTime := time.Now()
	log.Printf("%d entries. time index .. %s", dirlist.Length, endTime.Sub(startTime))

}
Ejemplo n.º 2
0
func main() {

	/*if strings.HasSuffix(*dir, "/") == false {
		*dir = *dir + "/"
	}*/
	flag.Parse()

	llista = fuzzyfs.NewDirList()
	llista.MaxDepth = *depth
	if *mode == 1 {
		llista.PathSelect = fuzzyfs.DirsAndSymlinksAsDirs
	} else {
		llista.PathSelect = fuzzyfs.AllFiles
	}

	go func() {
		startTime := time.Now()
		fmt.Printf("Building index...%s\n", *dirpath)
		err := llista.Populate(*dirpath, nil)
		if err != nil {
			panic(err)
		}
		endTime := time.Now()
		fmt.Printf("Total list entries: %d\n", llista.GetLength())
		fmt.Println("time indexing...", endTime.Sub(startTime))

	}()

	mux := http.NewServeMux()
	mux.Handle("/", http.HandlerFunc(handleRequest))
	http.ListenAndServe("localhost:8888", mux)

	//pprof.WriteHeapProfile(f)
	//fmt.Print(llista)
	//for r := 0; r < llista.length; r++ {
	//  fmt.Println(llista.List[r].Path())
	//}

}
Ejemplo n.º 3
0
func main() {

	flag.Parse()

	dir := *path

	if _, err := os.Stat(dir); err != nil {
		log.Fatalf("Directory %s not exist", dir)
	}

	if strings.HasSuffix(dir, "/") == false {
		dir = dir + "/"
	}

	if *verbose == false {
		log.SetOutput(ioutil.Discard)
	}

	index_loaded := false
	var llista *fuzzyfs.DirList
	// Check if gob index exists... or command reindex
	if _, err := os.Stat(dir + *index_file); err != nil || *reindex == true {

		startTime := time.Now()
		log.Print("Regenerating index")
		llista = fuzzyfs.NewDirList()
		llista.MaxDepth = *depth

		if *method == 1 {
			llista.PathSelect = fuzzyfs.AllFiles
		} else {
			llista.PathSelect = fuzzyfs.DirsAndSymlinksAsDirs
			log.Print("Indexing... dirs and symlinks")
		}

		llista.Populate(dir, nil)

		log.Printf("Found %d files", llista.Length)

		f, err := os.Create(dir + *index_file)
		if err != nil {
			log.Fatalf("Unable to create index %s", err)
		}
		defer f.Close()

		enc := gob.NewEncoder(f)
		enc.Encode(&llista)

		endTime := time.Now()
		log.Printf("Index generated in %s\n", endTime.Sub(startTime))
		index_loaded = true

		if *reindex == true {
			os.Exit(0)
		}

	}

	startTime := time.Now()
	if index_loaded == false {
		f, err := os.Open(dir + *index_file)
		if err != nil {
			log.Fatalf("Unable to load index %s", err)
		}
		defer f.Close()

		enc := gob.NewDecoder(f)
		err = enc.Decode(&llista)
	}

	q := *query
	u := *umbral

	res := llista.Query(q, u)

	for _, r := range res {
		fmt.Println(dir + r.Path)
	}

	//fmt.Print(res)
	endTime := time.Now()
	log.Print(fmt.Sprint("ElapsedTime:", endTime.Sub(startTime), "\n"))
	log.Printf("Total files: %d\n", llista.Length)

}