// callerPkgDir returns a pathname containing the build-time location of the
// deepest calling function that is not within this package. If that cannot be
// found, ok will be false and dir will be empty.
559347
func callerPkgDir() (dir string, ok bool) {
	_, thisFile, _, cok := runtime.Caller(0) // /home/me/workspace/src/fastly/go-utils/tls/tls.go
	if !cok {
		return
	}

	thisDir := filepath.Dir(thisFile)                                 // /home/me/workspace/src/fastly/go-utils/tls
	sep := fmt.Sprintf("%csrc%c", os.PathSeparator, os.PathSeparator) // /src/
	p := strings.SplitN(thisDir, sep, 2)
	if len(p) < 2 {
		return
	}
	thisPkg := p[1] // fastly/go-utils/tls/

	for i := 1; ; i++ {
		if i > 10 {
			// typical stack is tls.ConfigureServer -> tls.GenerateConfig ->
			// tls.LoadPackagedKeypair -> tls.LocatePackagedPEMFile ->
			// tls.LocatePackagedPEMDir -> tls.searchUpwards
			panic("excessive recursion inside tls package")
		}

		_, file, _, cok := runtime.Caller(i) // /home/me/workspace/src/foo/bar/subpkg/thing.go
		if !cok {
			return
		}

		if !strings.Contains(file, thisPkg) {
			return filepath.Dir(file), true // /home/me/workspace/src/foo/bar/subpkg
		}
	}
}
1169668
func pkgPrefix(funcName string) string {
	const pathSep = "/"
	end := strings.LastIndex(funcName, pathSep)
	if end == -1 {
		return ""
	}
	return funcName[:end]
}
1034152
func newDPKG() (packageManager, bool) {
	_, err := exec.LookPath("dpkg-query")
	if err != nil {
		return nil, false
	}
	return dpkg{}, true
}
286374
func (pb *PackageBuilder) addFileToWorkingDir(metaName string, fpath string) (err error) {
	// Get relative dir from source
	srcDir := filepath.Dir(filepath.Dir(fpath))
	for _, mp := range metapaths {
		if metaName == mp.name && mp.hasFolder {
			srcDir = filepath.Dir(srcDir)
		}
	}
	frel, _ := filepath.Rel(srcDir, fpath)

	// Try to find meta file
	hasMeta := true
	fmeta := fpath + "-meta.xml"
	fmetarel := ""
	if _, err = os.Stat(fmeta); err != nil {
		if os.IsNotExist(err) {
			hasMeta = false
		} else {
			// Has error
			return
		}
	} else {
		// Should be present since we worked back to srcDir
		fmetarel, _ = filepath.Rel(srcDir, fmeta)
	}

	fdata, err := ioutil.ReadFile(fpath)
	if err != nil {
		return
	}

	pb.Files[frel] = fdata
	if hasMeta {
		fdata, err = ioutil.ReadFile(fmeta)
		pb.Files[fmetarel] = fdata
		return
	}

	return
}
898386
func caller(depth int) string {
	if _, file, line, ok := runtime.Caller(depth); ok {
		return fmt.Sprint(filepath.Base(file), ":", line)
	}
	return "???:0"
}
93115
func packageFilenameLine(ld *LineData, depth int) {
	i, filename, linenum, ok := runtime.Caller(depth)
	if !ok {
		return
	}

	// Strip the directory from the filename. Even on Windows this is slash
	// delimited. See https://github.com/golang/go/issues/3335.
	fileParts := strings.Split(filename, "/")
	ld.SourceFile = fileParts[len(fileParts)-1]
	ld.SourceLine = linenum

	// Set up params from the call stack.
	f := runtime.FuncForPC(i)
	if f == nil {
		return
	}

	// generate the separate package name and function name
	packagePath := strings.Split(f.Name(), "/")
	n := len(packagePath)
	pkgFunc := strings.SplitN(packagePath[n-1], ".", 2)
	if len(pkgFunc) != 2 {
		return
	}

	pkg := strings.Join(packagePath[:n-1], "/") + fmt.Sprintf("/%s", pkgFunc[0])
	ld.CallingPackage = pkg
	ld.CallingFunction = pkgFunc[1]
}
1154224
func LocalDir(p string) string {
	homeDir := ServiceDHome()
	return path.Join(homeDir, p)
}
29814
func (c *C) MkDir() string {
	path := c.tempDir.newPath()
	if err := os.Mkdir(path, 0700); err != nil {
		panic(fmt.Sprintf("Couldn't create temporary directory %s: %s", path, err.Error()))
	}
	return path
}
801265
func GodelPropsDistPkgInfo(projectDir string) (godelgetter.PkgSrc, error) {
	wrapperSpec, err := specdir.New(projectDir, layout.WrapperSpec(), nil, specdir.Validate)
	if err != nil {
		return nil, errors.Wrapf(err, "unable to create wrapper spec")
	}
	configDir := wrapperSpec.Path(layout.WrapperConfigDir)

	propsFilePath := path.Join(configDir, fmt.Sprintf("%s.properties", layout.AppName))
	props, err := readPropertiesFile(propsFilePath)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to read properties file %s", propsFilePath)
	}
	url, ok := props[propertiesURLKey]
	if !ok {
		return nil, errors.Wrapf(err, "properties file %s does not contain key %s", propsFilePath, propertiesURLKey)
	}
	checksum := props[propertiesChecksumKey]
	return godelgetter.NewPkgSrc(url, checksum), nil
}
1281479
func (g GlobalConfig) ProjectDir() (string, error) {
	if g.Wrapper == "" {
		return "", errors.Errorf("wrapper must be specified to determine project directory")
	}
	return path.Dir(g.Wrapper), nil
}
330372
func Mkdir(name string, perm os.FileMode) error {
	return mkdir(name, perm)
}
152880
func pkgForPath(path string) *build.Package {
	// get pwd for relative imports
	pwd, err := os.Getwd()
	if err != nil {
		fmt.Printf("error getting pwd (required for relative imports): %s\n", err)
		os.Exit(1)
	}

	// read full package information
	pkg, err := build.Import(path, pwd, 0)
	if err != nil {
		fmt.Printf("error reading package: %s\n", err)
		os.Exit(1)
	}

	return pkg
}
481154
func GuessPackageFromDir(dir string) (pkg *build.Package, err error) {
	absdir, err := filepath.Abs(dir)
	if err != nil {
		return
	}

	dirsplit := strings.Split(absdir, string(os.PathSeparator))
	for i, n := 1, len(dirsplit); i < n; i++ {
		trypath := strings.Join(dirsplit[i:], string(os.PathSeparator))
		if pkg, err = build.Import(trypath, absdir, 0); err == nil {
			return
		}
	}

	return nil, ErrorImpossibleImportDir1.New(nil, absdir)
}
1140308
func (c *Client) Mkdir(name string) error {
	_, err := c.Files.CreateFolder(&dropbox.CreateFolderInput{name})
	return err
}
1351216
func getCaller() *runtime.Frame {

	// cache this package's fully-qualified name
	callerInitOnce.Do(func() {
		pcs := make([]uintptr, 2)
		_ = runtime.Callers(0, pcs)
		logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name())

		// now that we have the cache, we can skip a minimum count of known-logrus functions
		// XXX this is dubious, the number of frames may vary
		minimumCallerDepth = knownLogrusFrames
	})

	// Restrict the lookback frames to avoid runaway lookups
	pcs := make([]uintptr, maximumCallerDepth)
	depth := runtime.Callers(minimumCallerDepth, pcs)
	frames := runtime.CallersFrames(pcs[:depth])

	for f, again := frames.Next(); again; f, again = frames.Next() {
		pkg := getPackageName(f.Function)

		// If the caller isn't part of this package, we're done
		if pkg != logrusPackage {
			return &f
		}
	}

	// if we got here, we failed to find the caller's context
	return nil
}
1029863
func (fs MountFS) Mkdir(name string, perm os.FileMode) error {
	mount, innerPath := findMount(name, fs.mounts, fs.rootFS, string(fs.PathSeparator()))
	return mount.Mkdir(innerPath, perm)
}
902683
func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (
	node fs.Node, err error) {
	ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Mkdir",
		fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name))
	defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }()

	d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Mkdir %s", req.Name)
	defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }()

	// This fits in situation 1 as described in libkbfs/delayed_cancellation.go
	err = libcontext.EnableDelayedCancellationWithGracePeriod(
		ctx, d.folder.fs.config.DelayedCancellationGracePeriod())
	if err != nil {
		return nil, err
	}

	newNode, _, err := d.folder.fs.config.KBFSOps().CreateDir(
		ctx, d.node, req.Name)
	if err != nil {
		return nil, err
	}

	child := newDir(d.folder, newNode)
	d.folder.nodesMu.Lock()
	d.folder.nodes[newNode.GetID()] = child
	d.folder.nodesMu.Unlock()
	return child, nil
}