// stripVendorPath strips the vendor dir prefix from a package path.
// For example we might encounter an absolute path like
// github.com/foo/bar/vendor/github.com/pkg/errors which is resolved
// to github.com/pkg/errors.
169144
func stripVendorPath(p string) string {
	parts := strings.Split(p, "/vendor/")
	if len(parts) == 1 {
		return p
	}
	return strings.TrimLeft(path.Join(parts[1:]...), "/")
}
1244387
func (c Context) StripExt(path string) string {
	for i := len(path) - 1; i >= 0 && path[i] != '/'; i-- {
		if path[i] == '.' {
			return path[:i]
		}
	}
	return path
}
1275814
func (ctx *Context) VendorFilePackagePath(path string) *vendorfile.Package {
	for _, pkg := range ctx.VendorFile.Package {
		if pkg.Remove {
			continue
		}
		if pkg.Path == path {
			return pkg
		}
	}
	return nil
}
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
}
217844
func (f File) HasVendoredCodeChanges() bool {
	return strings.HasPrefix(string(f), "Godeps/_workspace") ||
		strings.HasPrefix(string(f), "vendor") ||
		strings.HasPrefix(string(f), "pkg/build/vendor")
}
545332
func PackagePath(path string) (string, error) {
	absPath, err := filepath.Abs(path)
	if err != nil {
		absPath = path
	}
	gopaths := filepath.SplitList(envOr("GOPATH", build.Default.GOPATH))
	if os.Getenv("GO111MODULE") != "on" { // GOPATH mode
		for _, gopath := range gopaths {
			if gp, err := filepath.Abs(gopath); err == nil {
				gopath = gp
			}
			if filepath.HasPrefix(absPath, gopath) {
				base := filepath.FromSlash(gopath + "/src")
				rel, err := filepath.Rel(base, absPath)
				return filepath.ToSlash(rel), err
			}
		}
	}
	if os.Getenv("GO111MODULE") != "off" { // Module mode
		root, file := findModuleRoot(absPath, "", false)
		if root != "" {
			content, err := ioutil.ReadFile(filepath.Join(root, file))
			if err == nil {
				p := modulePath(content)
				base := filepath.FromSlash(root)
				rel, err := filepath.Rel(base, absPath)
				return filepath.ToSlash(filepath.Join(p, rel)), err
			}
		}
	}
	return "", fmt.Errorf("%s does not contain a Go package", absPath)
}
478752
func stripPrefix(prefix, path string) (string, bool) {
	if !strings.HasPrefix(path, prefix) {
		return "", false
	}

	path = path[len(prefix):]
	if path == "" {
		return "", false
	}

	return path, true
}
717730
func PackagePaths(root string, exclude *regexp.Regexp) ([]string, error) {
	if strings.HasSuffix(root, "...") {
		root = root[0 : len(root)-3]
	} else {
		return []string{root}, nil
	}
	paths := map[string]bool{}
	err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
		if filepath.Ext(path) == ".go" {
			path = filepath.Dir(path)
			if exclude != nil && exclude.MatchString(path) {
				return nil
			}
			paths[path] = true
		}
		return nil
	})
	if err != nil {
		return []string{}, err
	}

	result := []string{}
	for path := range paths {
		result = append(result, path)
	}
	return result, nil
}
596201
func ConfigDirPath(projectDirPath string) (string, error) {
	if projectDirPath == "" {
		return "", errors.Errorf("projectDirPath was empty")
	}
	wrapper, err := specdir.New(projectDirPath, layout.WrapperSpec(), nil, specdir.Validate)
	if err != nil {
		return "", err
	}
	return wrapper.Path(layout.WrapperConfigDir), nil
}
149727
func projectPath(inputPath string) string {
	// if no path is provided... assume CWD.
	if inputPath == "" {
		x, err := os.Getwd()
		if err != nil {
			er(err)
		}

		return x
	}

	var projectPath string
	var projectBase string
	srcPath := srcPath()

	// if provided, inspect for logical locations
	if strings.ContainsRune(inputPath, os.PathSeparator) {
		if filepath.IsAbs(inputPath) || filepath.HasPrefix(inputPath, string(os.PathSeparator)) {
			// if Absolute, use it
			projectPath = filepath.Clean(inputPath)
			return projectPath
		}
		// If not absolute but contains slashes,
		// assuming it means create it from $GOPATH
		count := strings.Count(inputPath, string(os.PathSeparator))

		switch count {
		// If only one directory deep, assume "github.com"
		case 1:
			projectPath = filepath.Join(srcPath, "github.com", inputPath)
			return projectPath
		case 2:
			projectPath = filepath.Join(srcPath, inputPath)
			return projectPath
		default:
			er(errors.New("Unknown directory"))
		}
	}

	// hardest case.. just a word.
	if projectBase == "" {
		x, err := os.Getwd()
		if err == nil {
			projectPath = filepath.Join(x, inputPath)
			return projectPath
		}
		er(err)
	}

	projectPath = filepath.Join(srcPath, projectBase, inputPath)
	return projectPath
}
274799
func (s *Spec) rewritePackageName(pkg *Package) error {
	pkgName := filepath.Base(s.Name)
	if s.Local {
		pkgName = os.Getenv("GOPACKAGE")
		if pkgName == "" {
			return errors.New("GOPACKAGE cannot be empty")
		}
	}
	for _, node := range pkg.Files {
		node.Name.Name = pkgName
	}
	return nil
}
199186
func trimPackagePrefix(file string) string {
	if l := strings.LastIndex(file, "/vendor/"); l >= 0 {
		return file[l+len("/vendor/"):]
	}
	if l := strings.LastIndex(file, "/src/"); l >= 0 {
		return file[l+5:]
	}
	if l := strings.LastIndex(file, "/pkg/"); l >= 0 {
		return file[l+1:]
	}
	return file
}
895820
func (repo *Repository) PatchPath(index int64) (string, error) {
	if err := repo.GetOwner(); err != nil {
		return "", err
	}

	return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil
}
784216
func (a *API) ImportPath() string {
	return path.Join(a.BaseImportPath, a.PackageName())
}
546283
func relPathToRelGoPath(modAbsPath, absPath string) string {
	if absPath == "." {
		return ""
	}

	path := strings.TrimPrefix(absPath, modAbsPath)
	pathItems := strings.Split(path, string(filepath.Separator))
	return strings.Join(pathItems, "/")
}
547908
func recordPathForVaultKey(key string) string {
	if strings.Contains(key, "/") {
		return pkgPath.Dir(key)
	}
	return DynamoDBEmptyPath
}
922803
func (r *Router) subPath(p string) string {
	pre := r.prefix

	if (pre == "/" || pre[:len(pre)-1] == "/") && p[:1] == "/" {
		pre = pre[:len(pre)-1]
	}

	return pre + p
}