Esempio n. 1
0
func init() {
	flag.Parse()

	SetLogLevel(*verbose)

	daemonMode := *httpAddr != ""

	if *showHelp || (!daemonMode && flag.NArg() == 0) {
		PrintHelp(pkg, version, about, usage)
		os.Exit(0)
	}

	var fuzzyCost fuzzy.LevenshteinCost
	var fuzzyThreshold int

	if *levenshteinParams != "" {
		n, err := fmt.Sscanf(*levenshteinParams, "%d,%d,%d,%d", &fuzzyThreshold, &fuzzyCost.Del, &fuzzyCost.Ins, &fuzzyCost.Subs)
		if err != nil {
			log.Fatal(err)
		}
		if n != 4 {
			Errorf("Invalid number of fields for fuzzy search parameter.\n")
		}
	}

	tpl = template.Must(template.New("result").Parse(*templateString + "\n"))

	options := locate.Options{
		IgnoreCase:           *ignoreCase,
		MaxMatches:           *limit,
		StripExtension:       *stripExtension,
		Basename:             *basenameMustMatch,
		StripPath:            *stripPath,
		Existing:             *existing, // We handle this manually, after getting the list of matches.
		Accessable:           *accessable,
		Symlink:              *symlinkCandidates,
		HashMap:              strings.Contains(*searchMethod, "hashmap"),
		LevenshteinCost:      fuzzyCost,
		LevenshteinThreshold: fuzzyThreshold,
		NWorkers:             *nworkers,
		Root:                 *root,
	}

	var err error
	t0 := time.Now()
	db, err = locate.NewDB(strings.Split(*dbFiles, ":"), &options)
	t1 := time.Now()
	Logln("Loaded", *dbFiles, "in", float64(t1.Sub(t0))/1e9, "seconds")
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 2
0
func init() {
	flag.Parse()

	SetLogLevel(*verbose)

	if *showHelp {
		PrintHelp(pkg, version, about, usage)
		os.Exit(0)
	}

	mulmap := map[string]int64{"B": 1, "K": 1024, "M": 1024 * 1024, "G": 1024 * 1024 * 1024, "T": 1024 * 1024 * 1024 * 1024}

	var ok bool
	if multiplier, ok = mulmap[*unit]; !ok {
		log.Fatal("Invalid unit", *unit)
	}
	minSize = filesize(int64(*_minSize) * multiplier)

	options := locate.Options{
		IgnoreCase: *ignoreCase,
		Basename:   false,
		StripPath:  false,
		Existing:   *existing, // We handle this manually, after getting the list of matches.
		Accessable: *accessable,
		Symlink:    false,
		HashMap:    true,
		NWorkers:   *nworkers,
		Root:       *root,
	}

	var err error
	db, err = locate.NewDB(strings.Split(*dbFiles, ":"), &options)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 3
0
func init() {
	var err error

	missingTargets = make(map[string]bool)
	brokenLinks = make(map[string]string)

	flag.Parse()

	SetLogLevel(*verbose)

	if *showVersion {
		PrintVersion(pkg, version, author)
		os.Exit(0)
	}
	if *showHelp || flag.NArg() == 0 {
		PrintHelp(pkg, version, about, usage)
		os.Exit(0)
	}

	Logf("It's recommended that you update your database files by updatedb(8) prior to execution.\n")

	if *filter != "" {
		filters := strings.Split(*filter, "\n")
		filterIn = make([]*regexp.Regexp, 0, len(filters))
		filterOut = make([]*regexp.Regexp, 0, len(filters))

		for _, f := range filters {
			if f[0] == '!' {
				filterOut = append(filterOut, regexp.MustCompile(f[1:]))
			} else {
				filterIn = append(filterIn, regexp.MustCompile(f))
			}
		}
	}

	var fuzzyCost fuzzy.LevenshteinCost
	var fuzzyThreshold int

	if *levenshteinParams != "" {
		n, err := fmt.Sscanf(*levenshteinParams, "%d,%d,%d,%d", &fuzzyThreshold, &fuzzyCost.Del, &fuzzyCost.Ins, &fuzzyCost.Subs)
		if err != nil {
			log.Fatal(err)
		}
		if n != 4 {
			Errorf("Invalid number of fields for fuzzy search parameter.\n")
		}
	}

	options := locate.Options{
		IgnoreCase:           *ignoreCase,
		MaxMatches:           *limit,
		StripExtension:       *stripExtension,
		Basename:             *basenameMustMatch,
		StripPath:            *stripPath,
		Existing:             *existing, // We handle this manually, after getting the list of matches.
		Symlink:              *symlinkCandidates,
		HashMap:              strings.Contains(*searchMethod, "hashmap"),
		LevenshteinCost:      fuzzyCost,
		LevenshteinThreshold: fuzzyThreshold,
		NWorkers:             *nworkers,
		Root:                 *root,
	}

	if *replaceFile != "" {
		replacer, err = NewReplacer(*replaceFile)
		if err != nil {
			log.Fatal(err)
		}
		Logln("Read replacement rules:")
		for _, r := range replacer.rules {
			Logln("*", r)
			if r.method == "hashmap" {
				options.HashMap = true
			}
		}
	}

	Logf("Reading databases...\n")
	timeStart := time.Now()
	db, err = locate.NewDB(filepath.SplitList(*dbPath), &options)
	timeEnd := time.Now()
	Logf("Done. Took %.2f seconds.\n", float64(timeEnd.Sub(timeStart))/1e9)
	if err != nil {
		log.Fatal(err)
	}
}