Ejemplo n.º 1
0
func RunIndex(dbpath string, backend_type string, args []string) {
	runtime.GOMAXPROCS(runtime.NumCPU())
	mystore, err := store.NewStore("leveldb", dbpath)
	check(err)
	defer mystore.Close()

	for _, path := range args {
		mybackend := backend.NewBackend(backend_type)
		matches, err := filepath.Glob(path)
		check(err)
		for _, fp := range matches {
			err = Index(mystore, mybackend, fp)
			check(err)
		}
	}
}
Ejemplo n.º 2
0
func (i *Indexer) IndexOne(filename string, checkGrowing bool) error {
	_, alreadyIndexed := i.indexedFilenames[filename]
	if alreadyIndexed {
		return nil
	}
	if checkGrowing {
		stillGrowing, err := isFileGrowing(filename)
		if err != nil {
			log.Printf("Failed to check if %q is growing: %q", filename, err)
			return err
		}
		if stillGrowing {
			log.Printf("Skipping still growing file %q\n", filename)
			return nil
		}
	}

	dbPath, err := i.FilenameToDatabaseFilename(filename)
	if err != nil {
		log.Printf("Can't convert %q to database filename: %q", filename, err)
		return err
	}
	s, err := i.OpenOrCreateStore(dbPath)
	if err != nil {
		log.Printf("Error opening database %q %q", dbPath, err)
		return err
	}
	mybackend := backend.NewBackend(i.config.Backend)
	err = Index(*s, mybackend, filename)
	if err != nil {
		log.Printf("Error indexing %q %q", filename, err)
		return err
	}
	i.indexedFilenames[filename] = true
	return nil
}