// goGetFiles returns a list of files that are in given packages. File
// paths are relative to a given directory.
330448
func goGetFiles(dir string, pkgs []string) []string {
	params := []string{
		"Dir",
		"GoFiles",
		"CgoFiles",
	}
	var allFiles []string
	rawTuples := goRun(goList(params, pkgs))
	for _, raw := range rawTuples {
		tuple := goSliceRawTuple(raw)
		moduleDir := filepath.Clean(tuple[0])
		dirSep := fmt.Sprintf("%s%c", dir, filepath.Separator)
		moduleDirSep := fmt.Sprintf("%s%c", moduleDir, filepath.Separator)
		if !strings.HasPrefix(moduleDirSep, dirSep) {
			continue
		}
		relModuleDir, err := filepath.Rel(dir, moduleDir)
		if err != nil {
			common.Die("Could not make a relative path from %q to %q, even if they have the same prefix", moduleDir, dir)
		}
		files := append(goSliceRawSlice(tuple[1]), goSliceRawSlice(tuple[2])...)
		for i := 0; i < len(files); i++ {
			files[i] = filepath.Join(relModuleDir, files[i])
		}
		allFiles = append(allFiles, files...)
	}
	return allFiles
}
1176614
func (p *Predict) paths(path string, includeFiles bool) []string {
	client := p.Client()
	if client == nil {
		return nil
	}

	// Vault does not support listing based on a sub-key, so we have to back-pedal
	// to the last "/" and return all paths on that "folder". Then we perform
	// client-side filtering.
	root := path
	idx := strings.LastIndex(root, "/")
	if idx > 0 && idx < len(root) {
		root = root[:idx+1]
	}

	paths := p.listPaths(root)

	var predictions []string
	for _, p := range paths {
		// Calculate the absolute "path" for matching.
		p = root + p

		if strings.HasPrefix(p, path) {
			// Ensure this is a directory or we've asked to include files.
			if includeFiles || strings.HasSuffix(p, "/") {
				predictions = append(predictions, p)
			}
		}
	}

	// Add root to the path
	if len(predictions) == 0 {
		predictions = append(predictions, path)
	}

	return predictions
}
355080
func FGet(f *os.File, name string) ([]byte, error) {
	return get(f.Name(), name, func(name string, data []byte) (int, error) {
		return fgetxattr(f, name, data)
	})
}
525280
func Paths(path string, recurse bool) (paths []string, err error) {
	err = filepath.Walk(path, func(f string, info os.FileInfo, err error) error {
		if !recurse {
			if path != f && path != filepath.Dir(f) {
				return filepath.SkipDir
			}
		}
		paths = append(paths, f)
		return nil
	})
	return paths, err
}
746958
func (rt *requireTree) GetList(extInfo *types.ExtensionInfo) (requiredFiles []string, lastModified int64, err error) {
	finalPath := rt.Path
	if !filepath.IsAbs(finalPath) {
		finalPath = filepath.Join(rt.BaseDir, rt.Path)
		if newPath, err := filepath.EvalSymlinks(finalPath); err == nil {
			finalPath = newPath
		}
	}
	alterExts := extInfo.AlterExts
	if alterExts.Len() == 0 {
		return nil, 0, errors.New("Extension Format unknown for require:" + extInfo.CurrentExtension)
	}
	err = filepath.Walk(finalPath, func(walkpath string, f os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if modified := f.ModTime().Unix(); lastModified < modified {
			lastModified = modified
		}
		if f.IsDir() {
			return nil
		}
		curExt := filepath.Ext(walkpath)
		if curExt == extInfo.CurrentExtension {
			requiredFiles = append(requiredFiles, walkpath)
			return nil
		}
		for e := alterExts.Front(); e != nil; e = e.Next() {
			if e.Value == curExt {
				requiredFiles = append(requiredFiles, walkpath)
				break
			}
		}
		return nil
	})
	if err != nil {
		return nil, 0, err
	}
	sort.Strings(requiredFiles)
	return
}
615983
func (p *Packfile) GetAll() (storer.EncodedObjectIter, error) {
	return p.GetByType(plumbing.AnyObject)
}
1062457
func CollectPackages(infos map[string]*FileInfo, protos []string, importDirs []string) (map[string]*PackageInfo, error) {
	pkgMap := map[string]*PackageInfo{}

	// Collect into packages.
	for _, info := range infos {
		packageInfo, ok := pkgMap[info.ComputedPackage]
		if !ok {
			packageInfo = &PackageInfo{ComputedPackage: info.ComputedPackage}
			pkgMap[info.ComputedPackage] = packageInfo
		}
		packageInfo.Files = append(packageInfo.Files, info)
	}

	// Collect deps for each package.
	for _, pkg := range pkgMap {
		deps := map[string]*FileInfo{}
		for _, info := range pkg.Files {
			for _, dep := range info.Deps {
				deps[dep] = infos[dep]
			}
		}
		for _, dep := range deps {
			pkg.Deps = append(pkg.Deps, dep)
		}
	}

	return pkgMap, nil
}
171747
func Geted() string {
	if dir, err := filepath.Abs(filepath.Dir(os.Args[0])); err == nil {
		return dir
	} else {
		panic("Failed to retrieve executable directory")
	}
}
671866
func goGetDeps(repo, module string) (string, []string) {
	pkg := path.Join(repo, module)
	rawTuples := goRun(goList([]string{"Dir", "Deps"}, []string{pkg}))
	if len(rawTuples) != 1 {
		common.Die("Expected to get only one line from go list for a single package")
	}
	tuple := goSliceRawTuple(rawTuples[0])
	dir := tuple[0]
	if module != "." {
		dirsToStrip := 1 + strings.Count(module, "/")
		for i := 0; i < dirsToStrip; i++ {
			dir = filepath.Dir(dir)
		}
	}
	dir = filepath.Clean(dir)
	deps := goSliceRawSlice(tuple[1])
	return dir, append([]string{pkg}, deps...)
}
740711
func globGetArgs(args []string) globArgs {
	f, target := standardFlags(globCmd)
	suffix := f.String("suffix", "", "File suffix (example: .go)")
	globbingMode := f.String("glob-mode", "all", "Which files to glob (normal, dot-files, all [default])")
	filelist := f.String("filelist", "", "Read all the files from this file")
	var mapTo []string
	mapToWrapper := common.StringSliceWrapper{Slice: &mapTo}
	f.Var(&mapToWrapper, "map-to", "Map contents of filelist to this directory, can be used multiple times")

	f.Parse(args)
	if *target == "" {
		common.Die("--target parameter must be specified and cannot be empty")
	}
	mode := globModeFromString(*globbingMode)
	if *filelist == "" {
		common.Die("--filelist parameter must be specified and cannot be empty")
	}
	if len(mapTo) < 1 {
		common.Die("--map-to parameter must be specified at least once")
	}
	return globArgs{
		target:   *target,
		suffix:   *suffix,
		mode:     mode,
		filelist: *filelist,
		mapTo:    mapTo,
	}
}
934567
func goFilesIn(dir string) ([]string, error) {
	pkg, err := build.ImportDir(dir, 0)
	if err != nil {
		return nil, fmt.Errorf("cannot process directory %s: %s", dir, err)
	}
	var names []string
	names = append(names, pkg.GoFiles...)
	names = append(names, pkg.CgoFiles...)
	names = prefixDirectory(dir, names)
	return names, nil
}
1129617
func (m *Mounter) GetSourcePaths() []string {
	m.Lock()
	defer m.Unlock()

	sourcePaths := make([]string, len(m.mounts))
	i := 0
	for path := range m.mounts {
		sourcePaths[i] = path
		i++
	}
	return sourcePaths
}
1352165
func ParsePackagePaths(srcDir string, paths ...string) (pkglist *PackageList, err error) {
	var pkg *build.Package
	pkglist = &PackageList{}
	if srcDir, err = filepath.Abs(srcDir); err != nil {
		return
	}

	if len(paths) < 1 {
		if pkg, err = GuessPackageFromDir(srcDir); err != nil {
			return
		}
		pkglist.AddPackage(pkg)
		return
	}

	for _, pkgpath := range paths {
		importPath := strings.TrimSuffix(pkgpath, "/...")
		if importPath != pkgpath {
			if err = collectPackage(pkglist, importPath, srcDir); err != nil {
				return
			}
		} else {
			if pkg, err = build.Import(importPath, srcDir, 0); err != nil {
				return
			}
			pkglist.AddPackage(pkg)
		}
	}

	return
}
383274
func GetAllPaths(y *simpleyaml.Yaml) ([]string, error)  {
	InitialPath := make([]string, 0)
	AllPaths, err :=  GetAllExistingPaths(y, InitialPath)
	if err != nil {
		return nil, errors.New("Retrieving paths failed")
	}
	return AllPaths, nil
}
566838
func GetGoVars() (string, string, error) {
	gopath := os.Getenv("GOPATH")
	if gopath == "" {
		return "", "", errors.New("Please set the $GOPATH environment variable")
	}

	goroot := filepath.Clean(runtime.GOROOT())
	if goroot == "" {
		return "", "", errors.New("Please set $GOROOT environment variable")
	}

	return gopath, goroot, nil
}
1011916
func getFile(args *internal.ArgType, t *internal.TBuf) (*os.File, error) {
	var f *os.File
	var err error

	// determine filename
	var filename = strings.ToLower(t.Name) + args.Suffix
	if args.SingleFile {
		filename = args.Filename
	}
	filename = path.Join(args.Path, filename)

	// lookup file
	f, ok := files[filename]
	if ok {
		return f, nil
	}

	// default open mode
	mode := os.O_RDWR | os.O_CREATE | os.O_TRUNC

	// stat file to determine if file already exists
	fi, err := os.Stat(filename)
	if err == nil && fi.IsDir() {
		return nil, errors.New("filename cannot be directory")
	} else if _, ok = err.(*os.PathError); !ok && args.Append && t.TemplateType != internal.XOTemplate {
		// file exists so append if append is set and not XO type
		mode = os.O_APPEND | os.O_WRONLY
	}

	// skip
	if t.TemplateType == internal.XOTemplate && fi != nil {
		return nil, nil
	}

	// open file
	f, err = os.OpenFile(filename, mode, 0666)
	if err != nil {
		return nil, err
	}

	// file didn't originally exist, so add package header
	if fi == nil || !args.Append {
		// add build tags
		if args.Tags != "" {
			f.WriteString(`// +build ` + args.Tags + "\n\n")
		}

		// execute
		err = args.TemplateSet().Execute(f, "xo_package.go.tpl", args)
		if err != nil {
			return nil, err
		}
	}

	// store file
	files[filename] = f

	return f, nil
}
491218
func goGetPackageDeps(repo, module string) []string {
	dir, deps := goGetDeps(repo, module)
	return goGetFiles(dir, deps)
}