// FindFile searches all config directories and return the first found file.
437880
func (m *Manager) FindFile(name string, exts ...string) string {
	for _, dir := range m.dirs {
		for _, ext := range exts {
			p := filepath.Join(dir, name+ext)
			if files.Exist(p) {
				return p
			}
		}
	}
	return ""
}
80906
func Find(path string) (int64, error) {
	if path == "" {
		return 0, fmt.Errorf("invalid directory")
	}
	var counter byteCounter
	var stderr bytes.Buffer
	findCmd := exec.Command("find", path, "-xdev", "-printf", ".")
	findCmd.Stdout, findCmd.Stderr = &counter, &stderr
	if err := findCmd.Start(); err != nil {
		return 0, fmt.Errorf("failed to exec cmd %v - %v; stderr: %v", findCmd.Args, err, stderr.String())
	}
	if err := findCmd.Wait(); err != nil {
		return 0, fmt.Errorf("cmd %v failed. stderr: %s; err: %v", findCmd.Args, stderr.String(), err)
	}
	return counter.bytesWritten, nil
}
906832
func (e Entry) Find(filepath string) *Entry {
	resultnode := &e
	for _, path := range strings.Split(filepath, "/") {
		encoded, err := govis.Vis(path, DefaultVisFlags)
		if err != nil {
			return nil
		}
		resultnode = resultnode.Descend(encoded)
		if resultnode == nil {
			return nil
		}
	}
	return resultnode
}
675915
func (apiDef *APIDefinition) FindLibFile(name string) (string, string) {
	// search in it's document
	if filename, ok := apiDef.Uses[name]; ok {
		return "", filename
	}

	// search in included libraries
	for _, lib := range apiDef.Libraries {
		if filename, ok := lib.Uses[name]; ok {
			return filepath.Dir(lib.Filename), filename
		}
	}
	return "", ""
}
1358988
func (self *Config) WriteFile(fname string, perm os.FileMode, header string) error {
	file, err := os.OpenFile(fname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
	if err != nil {
		return err
	}

	buf := bufio.NewWriter(file)
	if err = self.write(buf, header); err != nil {
		return err
	}
	buf.Flush()

	return file.Close()
}
809082
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error) {
	// Append files' name together.
	fileNames := make([]string, 1, len(moreFiles)+1)
	fileNames[0] = fileName
	if len(moreFiles) > 0 {
		fileNames = append(fileNames, moreFiles...)
	}

	c = newConfigFile(fileNames)

	for _, name := range fileNames {
		if err = c.loadFile(name); err != nil {
			return nil, err
		}
	}

	return c, nil
}
1286516
func Find(fileName, targetFileName string) (*tar.Header, io.ReadCloser, error) {
	reader, err := newReader(fileName)
	if err != nil {
		return nil, nil, err
	}

	targetFileName = path.Clean(targetFileName)

	for {
		header, err := reader.reader.Next()
		if err == io.EOF {
			reader.Close()
			return nil, nil, os.ErrNotExist
		}
		if err != nil {
			reader.Close()
			return nil, nil, err
		}

		// If the file found is not a regular file we don't return a reader
		if targetFileName == path.Clean(header.Name) {
			if header.Typeflag == tar.TypeReg || header.Typeflag == tar.TypeRegA {
				return header, reader, nil
			}
			reader.Close()
			return header, nil, nil
		}
	}
}
1231372
func (*EmptyFolder) FindFiles(ctx context.Context, fi *dokan.FileInfo, ignored string, callback func(*dokan.NamedStat) error) (err error) {
	return nil
}
1288594
func findFirstMatchingFile(glob string) (string, error) {
	matches, e := filepath.Glob(glob)
	if e != nil {
		return "", e
	}

	if len(matches) >= 1 {
		return matches[0], nil
	}
	return "", nil
}
130611
func (c *ConfigParser) ReadFile(path string) (Obj, error) {
	if path == "" && c.Open == nil {
		return nil, errors.New("ReadFile of empty string but Open hook not defined")
	}
	c.touchedFiles = make(map[string]bool)
	var err error
	c.rootJSON, err = c.recursiveReadJSON(path)
	return c.rootJSON, err
}
1105465
func (d *Dir) Find(name string) (Entry, int, error) {
	for ii, v := range d.EntryNames {
		if v == name {
			return d.Entries[ii], ii, nil
		}
	}
	return nil, -1, os.ErrNotExist
}
120041
func (l *List) LoadFile(path string, options *ParserOption) ([]Rule, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return l.parse(f, options)
}
790500
func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), nil, cbool(force))
	runtime.KeepAlive(c)
	if ret < 0 {
		return MakeGitError(ret)
	}

	return nil
}
69703
func (c *Config) configFromFile(path string) error {
	_, err := toml.DecodeFile(path, c)
	return errors.Trace(err)
}
1061141
func ConfigFromFile(file string) (Config, error) {
	configData, err := ioutil.ReadFile(file)
	if err != nil {
		return Config{}, errors.WithStack(err)
	}
	config := Config{}

	if err := yaml.Unmarshal([]byte(configData), &config); err != nil {
		return Config{}, errors.Errorf("error unmarshaling YAML file %s: %s", file, err)
	}

	return config, validateConfig(config)
}
65825
func IsFile(path string) bool {
	fi, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			// not found
			return false
		}
		fmt.Printf("failed to check dir %s: %s\n", path, err)
		return false
	}

	return fi.Mode().IsRegular()
}
1158445
func OpenFile(path string) (*os.File, error) {
	newPath, err := NormalizePath(path)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	fi, err := os.Stat(newPath)
	if err != nil {
		return nil, trace.ConvertSystemError(err)
	}
	if fi.IsDir() {
		return nil, trace.BadParameter("%v is not a file", path)
	}
	f, err := os.Open(newPath)
	if err != nil {
		return nil, trace.ConvertSystemError(err)
	}
	return f, nil
}