// LogDir is where to log
493916
func LogDir(appName string) (string, error) {
	libDir, err := libraryDir()
	if err != nil {
		return "", err
	}
	return filepath.Join(libDir, "Logs"), nil
}
1282136
func CacheDir(appName string) (string, error) {
	if appName == "" {
		return "", fmt.Errorf("No app name for dir")
	}
	return filepath.Join(os.TempDir(), appName), nil
}
27611
func LogDist(a, b ID) int {
	lz := 0
	for i := range a {
		x := a[i] ^ b[i]
		if x == 0 {
			lz += 8
		} else {
			lz += bits.LeadingZeros8(x)
			break
		}
	}
	return len(a)*8 - lz
}
1326172
func HomeDir() string {
	failInTests()
	if runtime.GOOS == "windows" {
		return os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
	}
	return os.Getenv("HOME")
}
973377
func (c *Context) Pkgdir() string {
	return filepath.Join(c.Project.Pkgdir(), c.ctxString())
}
1167915
func (p *Probe) checkDir(c context.Context, dir string, selfDir os.FileInfo, env environ.Env) string {
	// If we have a self directory defined, ensure that "dir" isn't the same
	// directory. If it is, we will ignore this option, since we are looking for
	// something outside of the wrapper directory.
	if selfDir != nil {
		switch checkDirStat, err := os.Stat(dir); {
		case err == nil:
			// "dir" exists; if it is the same as "selfDir", we can ignore it.
			if os.SameFile(selfDir, checkDirStat) {
				logging.Debugf(c, "Candidate shares wrapper directory [%s]; skipping...", dir)
				return ""
			}

		case os.IsNotExist(err):
			logging.Debugf(c, "Candidate directory does not exist [%s]; skipping...", dir)
			return ""

		default:
			logging.Debugf(c, "Failed to stat candidate directory [%s]: %s", dir, err)
			return ""
		}
	}

	t, err := findInDir(p.Target, dir, env)
	if err != nil {
		return ""
	}

	// Make sure this file isn't the same as "self", if available.
	if p.SelfStat != nil {
		switch st, err := os.Stat(t); {
		case err == nil:
			if os.SameFile(p.SelfStat, st) {
				logging.Debugf(c, "Candidate [%s] is same file as wrapper; skipping...", t)
				return ""
			}

		case os.IsNotExist(err):
			// "t" no longer exists, so we can't use it.
			return ""

		default:
			logging.Debugf(c, "Failed to stat candidate path [%s]: %s", t, err)
			return ""
		}
	}

	if err := filesystem.AbsPath(&t); err != nil {
		logging.Debugf(c, "Failed to normalize candidate path [%s]: %s", t, err)
		return ""
	}

	// Try running the candidate command and confirm that it is not a wrapper.
	if p.CheckWrapper != nil {
		switch isWrapper, err := p.CheckWrapper(c, t, env); {
		case err != nil:
			logging.Debugf(c, "Failed to check if [%s] is a wrapper: %s", t, err)
			return ""

		case isWrapper:
			logging.Debugf(c, "Candidate is a wrapper: %s", t)
			return ""
		}
	}

	return t
}
992186
func PurgeLogs() {
	f := flag.Lookup("log_dir")
	if f == nil {
		panic("the logging module doesn't specify a log_dir flag")
	}

	if *keepLogs == 0*time.Second {
		return
	}
	logDir := f.Value.String()
	program := filepath.Base(os.Args[0])

	timer := time.NewTimer(*purgeLogsInterval)
	for range timer.C {
		purgeLogsOnce(time.Now(), logDir, program, *keepLogs)
	}
}
747731
func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error) {
	return ReadDir(a.Fs, dirname)
}
1125535
func MakeParentDirs(path string, mode os.FileMode, log Log) error {
	// 2nd return value here is filename (not an error), which is not needed
	dir, _ := filepath.Split(path)
	if dir == "" {
		return fmt.Errorf("No base directory")
	}
	return MakeDirs(dir, mode, log)
}
599671
func (c *Configuration) HookDir() (string, error) {
	if git.IsGitVersionAtLeast("2.9.0") {
		hp, ok := c.Git.Get("core.hooksPath")
		if ok {
			return tools.ExpandPath(hp, false)
		}
	}
	return filepath.Join(c.LocalGitStorageDir(), "hooks"), nil
}
233522
func (l *AuditLog) auditDirs() ([]string, error) {
	authServers, err := l.getAuthServers()
	if err != nil {
		return nil, trace.Wrap(err)
	}

	var out []string
	for _, serverID := range authServers {
		out = append(out, filepath.Join(l.DataDir, serverID))
	}
	return out, nil
}
1085334
func (DefaultFs) ReadDir(dirname string) ([]os.FileInfo, error) {
	return ioutil.ReadDir(dirname)
}
1038771
func initializeLogging(logFile, logLevel string) {
	log = backendLog.Logger("SRVR")
	exchanges.UseLogger(xcLogger)
	logDir, _ := filepath.Split(logFile)
	err := os.MkdirAll(logDir, 0700)
	if err != nil {
		log.Errorf("failed to create log directory: %v", err)
		os.Exit(1)
	}
	r, err := rotator.New(logFile, 10*1024, false, 3)
	if err != nil {
		log.Errorf("failed to create file rotator: %v\n", err)
		os.Exit(1)
	}
	logRotator = r
	if logLevel != "" {
		level, ok := slog.LevelFromString(logLevel)
		if ok {
			log.SetLevel(level)
			xcLogger.SetLevel(level)
		} else {
			log.Infof("Unable to assign logging level=%s. Falling back to level=info", logLevel)
		}
	}
}
1522
func initLogRotator(logFile string) {
	logDir, _ := filepath.Split(logFile)
	err := os.MkdirAll(logDir, 0700)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
		os.Exit(1)
	}
	r, err := rotator.New(logFile, 10*1024, false, 3)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
		os.Exit(1)
	}

	logRotator = r
}
30609
func (m *Map) scopedLogger() *logrus.Entry {
	return log.WithFields(logrus.Fields{logfields.Path: m.path, "name": m.name})
}
531217
func cleanupDir(ctx context.Context, storage StorageAPI, volume, dirPath string) error {
	var delFunc func(string) error
	// Function to delete entries recursively.
	delFunc = func(entryPath string) error {
		if !hasSuffix(entryPath, slashSeparator) {
			// Delete the file entry.
			err := storage.DeleteFile(volume, entryPath)
			logger.LogIf(ctx, err)
			return err
		}

		// If it's a directory, list and call delFunc() for each entry.
		entries, err := storage.ListDir(volume, entryPath, -1, "")
		// If entryPath prefix never existed, safe to ignore.
		if err == errFileNotFound {
			return nil
		} else if err != nil { // For any other errors fail.
			logger.LogIf(ctx, err)
			return err
		} // else on success..

		// Entry path is empty, just delete it.
		if len(entries) == 0 {
			err = storage.DeleteFile(volume, path.Clean(entryPath))
			logger.LogIf(ctx, err)
			return err
		}

		// Recurse and delete all other entries.
		for _, entry := range entries {
			if err = delFunc(pathJoin(entryPath, entry)); err != nil {
				return err
			}
		}
		return nil
	}
	err := delFunc(retainSlash(pathJoin(dirPath)))
	return err
}
452030
func CacheDir() string {
	d := os.Getenv(CacheEnv)
	if d != "" {
		return d
	}
	switch runtime.GOOS {
	case "windows":
		return filepath.Join(os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"), "magefile")
	default:
		return filepath.Join(os.Getenv("HOME"), ".magefile")
	}
}