// canonicalizeImportPath takes an import path and returns the actual package.
// It doesn't support nested vendoring.
764633
func canonicalizeImportPath(importPath string) importPathString {
	if !strings.Contains(importPath, "/vendor/") {
		return importPathString(importPath)
	}

	return importPathString(importPath[strings.Index(importPath, "/vendor/")+len("/vendor/"):])
}
563165
func CanonicalizeContext(val string) (string, error) {
	return readWriteCon(filepath.Join(getSelinuxMountPoint(), "context"), val)
}
380149
func (rp *RevelContainer) ResolveImportPath(importPath string) (string, error) {
	if rp.Packaged {
		return filepath.Join(rp.SourcePath, importPath), nil
	}

	modPkg, err := build.Import(importPath, rp.AppPath, build.FindOnly)
	if err != nil {
		return "", err
	}
	if rp.PackageInfo.Vendor && !strings.HasPrefix(modPkg.Dir,rp.BasePath) {
		return "", fmt.Errorf("Module %s was found outside of path %s.",importPath, modPkg.Dir)
	}
	return modPkg.Dir, nil
}
305451
func (c *CommandConfig) UpdateImportPath() error {
	var importPath string
	required := true
	switch c.Index {
	case NEW:
		importPath = c.New.ImportPath
	case RUN:
		importPath = c.Run.ImportPath
	case BUILD:
		importPath = c.Build.ImportPath
	case PACKAGE:
		importPath = c.Package.ImportPath
	case CLEAN:
		importPath = c.Clean.ImportPath
	case TEST:
		importPath = c.Test.ImportPath
	case VERSION:
		importPath = c.Version.ImportPath
		required = false
	}

	if len(importPath) == 0 || filepath.IsAbs(importPath) || importPath[0] == '.' {
		utils.Logger.Info("Import path is absolute or not specified", "path", importPath)
		// Try to determine the import path from the GO paths and the command line
		currentPath, err := os.Getwd()
		if len(importPath) > 0 {
			if importPath[0] == '.' {
				// For a relative path
				importPath = filepath.Join(currentPath, importPath)
			}
			// For an absolute path
			currentPath, _ = filepath.Abs(importPath)
		}

		if err == nil {
			for _, path := range strings.Split(build.Default.GOPATH, string(filepath.ListSeparator)) {
				utils.Logger.Infof("Checking import path %s with %s", currentPath, path)
				if strings.HasPrefix(currentPath, path) && len(currentPath) > len(path)+1 {
					importPath = currentPath[len(path)+1:]
					// Remove the source from the path if it is there
					if len(importPath) > 4 && strings.ToLower(importPath[0:4]) == "src/" {
						importPath = importPath[4:]
					} else if importPath == "src" {
						if c.Index != VERSION {
							return fmt.Errorf("Invlaid import path, working dir is in GOPATH root")
						}
						importPath = ""
					}
					utils.Logger.Info("Updated import path", "path", importPath)
				}
			}
		}
	}

	c.ImportPath = importPath
	utils.Logger.Info("Returned import path", "path", importPath, "buildpath", build.Default.GOPATH)
	if required && c.Index != NEW {
		if err := c.SetVersions(); err != nil {
			utils.Logger.Panic("Failed to fetch revel versions", "error", err)
		}
		if err:=c.FrameworkVersion.CompatibleFramework(c);err!=nil {
			utils.Logger.Fatal("Compatibility Error", "message", err,
				"Revel framework version", c.FrameworkVersion.String(), "Revel tool version", c.CommandVersion.String())
		}
		utils.Logger.Info("Revel versions", "revel-tool", c.CommandVersion.String(), "Revel Framework", c.FrameworkVersion.String())
	}
	if !required {
		return nil
	}
	if len(importPath) == 0  {
		return fmt.Errorf("Unable to determine import path from : %s", importPath)
	}
	return nil
}
866807
func ImportPaths(srcdir, cwd string, args []string) []string {
	args = importPathsNoDotExpansion(srcdir, cwd, args)
	var out []string
	for _, a := range args {
		if strings.Contains(a, "...") {
			pkgs, err := matchPackages(srcdir, a)
			if err != nil {
				fmt.Printf("could not load all packages: %v\n", err)
			}
			out = append(out, pkgs...)
			continue
		}
		out = append(out, a)
	}
	return out
}
240169
func (r *runtimeVerbose) pathFromGopath(path string) string {
	return filepath.Dir(path[len(r.Gopath)+len("/src/"):])
}
1328833
func isLocalImport(path string) bool {
	return path == "." || path == ".." || strings.HasPrefix(path, "./") || strings.HasPrefix(path, "../")
}
483018
func DeterminePackageName(importPath string) string {
	packageName := filepath.Base(importPath)
	if strings.HasSuffix(packageName, "-go") {
		packageName = packageName[:len(packageName)-3]
	}

	return strings.Map(func(c rune) rune {
		switch {
		case unicode.IsLetter(c), unicode.IsDigit(c):
			return c
		default:
			return '_'
		}
	}, packageName)
}
811524
func getPackageImportMap(astPackage *ast.Package) map[string]string {

	result := make(map[string]string)

	// Iterate files in this package
	// (There's also an *ast.Package.Imports property but it seems to be empty)
	for fileName, file := range astPackage.Files {
		// Iterate imports in this file
		for _, importSpec := range file.Imports {
			// Remove quotes
			packagePath := importSpec.Path.Value[1 : len(importSpec.Path.Value)-1]

			// Determine package name
			var packageName string
			if importSpec.Name != nil {
				// Package is aliased to another name
				packageName = importSpec.Name.Name

			} else {
				// Use the default name, the path's last element
				tmp := strings.Split(packagePath, "/")
				packageName = tmp[len(tmp)-1]
			}

			// Check for naming conflicts
			tmp, exists := result[packageName]
			if exists && tmp != packagePath {
				panic(fmt.Sprintf("Package naming conflict in %s: %s => %s, was already %s\n",
					fileName, packageName, tmp, packagePath))
			}

			result[packageName] = packagePath
		}

		// Add this file's local path to import list
		// - there may not be other references to this package
		tmp, exists := result[file.Name.Name]
		if exists && tmp != path.Dir(fileName) {
			fmt.Printf("WARNING: Possible package naming conflict in file %q: package %q "+
				"references both importdir %q and relative dir %q\n",
				fileName, file.Name.Name, tmp, path.Dir(fileName))
		}
		result[file.Name.Name] = path.Dir(fileName)
	}

	return result
}
907276
func (i importer) Import(path string) string {
	if imp, ok := i.imports[path]; ok {
		if imp.Name != nil {
			return imp.Name.Name
		}
		return filepath.Base(path)
	}

	name := i.ns.NewName(goast.DeterminePackageName(path))
	astImport := &ast.ImportSpec{
		Name: ast.NewIdent(name),
		Path: stringLiteral(path),
	}

	i.imports[path] = astImport
	return name
}
625788
func PackageAbsPath(p interface{}) (string, error) {
	switch t := p.(type) {
	case *types.Package:
		return PackageAbsPath(t.Path())
	case *ast.ImportSpec:
		return PackageAbsPath(t.Path.Value[1 : len(t.Path.Value)-1])
	case string:
		gopath := os.Getenv("GOPATH")
		for _, path := range filepath.SplitList(gopath) {
			fullPath := filepath.Join(path, "src", t)
			absPath, err := filepath.Abs(fullPath)
			if err != nil {
				continue
			}

			if _, err = os.Stat(fullPath); err != nil {
				continue
			}

			return absPath, nil
		}

		return "", fmt.Errorf("failed to find %q in GOPATH (%s)", t, gopath)
	}

	return "", fmt.Errorf("unsupported argument type for PackageFullPath: %T", p)
}
138405
func (p *Importer) Import(path string) (*types.Package, error) {
	return p.ImportFrom(path, ".", 0) // use "." rather than "" (see issue #24441)
}
776836
func vendorlessImportPath(ipath string, currentPackagePath string) (string, bool) {
	split := strings.Split(ipath, "vendor/")
	// no vendor in path
	if len(split) == 1 {
		return ipath, true
	}
	// this import path does not belong to the current package
	if currentPackagePath != "" && !strings.Contains(currentPackagePath, split[0]) {
		return "", false
	}
	// Devendorize for use in import statement.
	if i := strings.LastIndex(ipath, "/vendor/"); i >= 0 {
		return ipath[i+len("/vendor/"):], true
	}
	if strings.HasPrefix(ipath, "vendor/") {
		return ipath[len("vendor/"):], true
	}
	return ipath, true
}
463301
func canonicalizeHeader(headers map[string]string) string {
	var canonicalizedHeaders []string

	for k := range headers {
		if lower := strings.ToLower(k); strings.HasPrefix(lower, HeaderSLSPrefix1) || strings.HasPrefix(lower, HeaderSLSPrefix2) {
			canonicalizedHeaders = append(canonicalizedHeaders, lower)
		}
	}

	sort.Strings(canonicalizedHeaders)

	var headersWithValue []string

	for _, k := range canonicalizedHeaders {
		headersWithValue = append(headersWithValue, k+":"+headers[k])
	}
	return strings.Join(headersWithValue, "\n")
}
179775
func setRootImportPath(importPath, targetDir string) string {
	// use import path if not empty
	if len(importPath) > 0 {
		return importPath
	}

	// get GOPATH dir
	gopath, err := filepath.Abs(os.Getenv("GOPATH"))
	if err != nil {
		return ""
	}
	gopath = filepath.Join(gopath, "src")

	// get absolute target dir
	absTargetDir, err := filepath.Abs(targetDir)
	if err != nil {
		panic("invalid targetDir:" + err.Error())
	}

	// panic if user doesn't specify import path and target dir
	// not under GOPATH.
	if !strings.HasPrefix(absTargetDir, gopath) {
		panic("please specify '--import-path' or set '--dir' under your GOPATH")
	}

	// set import path
	newImportPath, err := filepath.Rel(gopath, absTargetDir)
	if err != nil {
		panic("failed to set import path automatically:" + err.Error())
	}

	// re-join because otherwise windows will use `\`
	return path.Join(strings.Split(newImportPath, string(filepath.Separator))...)
}
439753
func (ccpack *CDSPackage) InitFromPath(ccname string, ccversion string, path string) ([]byte, *pb.ChaincodeDeploymentSpec, error) {
	//incase ccpack is reused
	ccpack.reset()

	buf, err := GetChaincodePackageFromPath(ccname, ccversion, path)
	if err != nil {
		return nil, nil, err
	}

	ccdata, err := ccpack.InitFromBuffer(buf)
	if err != nil {
		return nil, nil, err
	}

	if err := ccpack.ValidateCC(ccdata); err != nil {
		return nil, nil, err
	}

	return ccpack.buf, ccpack.depSpec, nil
}
448795
func NewFilePath(packagePath string) *File {
	return &File{
		Group: &Group{
			multi: true,
		},
		name:    guessAlias(packagePath),
		path:    packagePath,
		imports: map[string]importdef{},
		hints:   map[string]importdef{},
	}
}