// PackagePath returns the Go package path for the directory that lives under the given absolute
// file path.
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)
}
973377
func (c *Context) Pkgdir() string {
	return filepath.Join(c.Project.Pkgdir(), c.ctxString())
}
588989
func (d *manifestDeployer) CharmPath(path string) string {
	return filepath.Join(d.charmPath, path)
}
695653
func (p PackageInfo) PackageDir() string {
	parts := strings.Split(p.ComputedPackage, ".")
	return filepath.Join(parts...)
}
264347
func (r *RepositoryContent) GetPath() string {
	if r == nil || r.Path == nil {
		return ""
	}
	return *r.Path
}
969299
func (h *Hook) Path() string {
	return filepath.Join(h.Dir, h.Type)
}
61241
func GetPkgFullPath(short string) (string, error) {
	name, ok := PackageNameList[short]
	if !ok {
		return "", fmt.Errorf("no match package import path with given short name: %s", short)
	}
	return name, 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
}
1374279
func packageApp(c *model.CommandConfig) (err error) {

	// Determine the run mode.
	mode := DefaultRunMode
	if len(c.Package.Mode) >= 0 {
		mode = c.Package.Mode
	}

	appImportPath := c.ImportPath
	revel_paths, err := model.NewRevelPaths(mode, appImportPath, "", model.NewWrappedRevelCallback(nil, c.PackageResolver))
	if err != nil {
		return
	}

	// Remove the archive if it already exists.
	destFile := filepath.Join(c.AppPath, filepath.Base(revel_paths.BasePath)+".tar.gz")
	if c.Package.TargetPath != "" {
		if filepath.IsAbs(c.Package.TargetPath) {
			destFile = c.Package.TargetPath
		} else {
			destFile = filepath.Join(c.AppPath, c.Package.TargetPath)
		}
	}
	if err := os.Remove(destFile); err != nil && !os.IsNotExist(err) {
		return utils.NewBuildError("Unable to remove target file", "error", err, "file", destFile)
	}

	// Collect stuff in a temp directory.
	tmpDir, err := ioutil.TempDir("", filepath.Base(revel_paths.BasePath))
	utils.PanicOnError(err, "Failed to get temp dir")

	// Build expects the command the build to contain the proper data
	if len(c.Package.Mode) >= 0 {
		c.Build.Mode = c.Package.Mode
	}
	c.Build.TargetPath = tmpDir
	c.Build.CopySource = c.Package.CopySource
	buildApp(c)

	// Create the zip file.

	archiveName, err := utils.TarGzDir(destFile, tmpDir)
	if err != nil {
		return
	}

	fmt.Println("Your archive is ready:", archiveName)
	return
}
190768
func appendPath(rootPath, childPath string) string {
	return strings.TrimRight(rootPath, "/") + "/" + strings.TrimLeft(childPath, "/")
}
712699
func (rule *Rule) Path() Ref {
	if rule.Module == nil {
		panic("assertion failed")
	}
	return rule.Module.Package.Path.Append(StringTerm(string(rule.Head.Name)))
}
1069103
func (r *SourceRepository) LocalPath() (string, error) {
	if len(r.localDir) > 0 {
		return r.localDir, nil
	}
	if r.url.IsLocal() {
		r.localDir = filepath.Join(r.url.LocalPath(), r.contextDir)
	} else {
		gitRepo := git.NewRepository()
		var err error
		if r.localDir, err = ioutil.TempDir("", "gen"); err != nil {
			return "", err
		}
		r.localDir, err = CloneAndCheckoutSources(gitRepo, r.url.StringNoFragment(), r.url.URL.Fragment, r.localDir, r.contextDir)
		if err != nil {
			return "", err
		}
	}
	if _, err := os.Stat(r.localDir); os.IsNotExist(err) {
		return "", fmt.Errorf("supplied context directory '%s' does not exist in '%s'", r.contextDir, r.url.String())
	}
	return r.localDir, nil
}
605226
func (fs FS) Path(p ...string) string {
	return filepath.Join(append([]string{string(fs)}, p...)...)
}
856757
func PackageSourcePath(pkg string) (string, error) {
	buildCtx := build.Default
	buildCtx.GOPATH = envOr("GOPATH", build.Default.GOPATH) // Reevaluate each time to be nice to tests
	wd, err := os.Getwd()
	if err != nil {
		wd = "."
	}
	p, err := buildCtx.Import(pkg, wd, 0)
	if err != nil {
		return "", err
	}
	return p.Dir, nil
}
166962
func AbsolutePath(datadir string, filename string) string {
	if filepath.IsAbs(filename) {
		return filename
	}
	return filepath.Join(datadir, filename)
}
3094
func Gopath() string {
	epath := os.Getenv("GOPATH")
	if epath == "" {
		// It's now safe to assume $HOME/go
		// thanks to Dave Cheney and the folks
		// who work on the standard library
		// https://github.com/golang/go/issues/17262
		path := fmt.Sprintf("%s/go", local.Home())
		return path
	} else if strings.Contains(epath, ":") {
		espl := strings.Split(epath, ":")
		if len(espl) <= 1 {
			return epath
		}
		// Here we will take the first gopath defined and use that
		return espl[0]
	}
	return epath
}
78858
func (store FileStore) binPath(id string) string {
	return filepath.Join(store.Path, id+".bin")
}