// Removes a directory only if its empty, handles long
// paths for windows automatically.
352552
func fsRemoveDir(ctx context.Context, dirPath string) (err error) {
	if dirPath == "" {
		logger.LogIf(ctx, errInvalidArgument)
		return errInvalidArgument
	}

	if err = checkPathLength(dirPath); err != nil {
		logger.LogIf(ctx, err)
		return err
	}

	if err = os.Remove((dirPath)); err != nil {
		if os.IsNotExist(err) {
			return errVolumeNotFound
		} else if isSysErrNotEmpty(err) {
			return errVolumeNotEmpty
		}
		logger.LogIf(ctx, err)
		return err
	}

	return nil
}
360504
func (c *Conf) Cleanup() (err error) {
	err = os.RemoveAll(c.dirPath)
	return
}
1007588
func EmptyAll(name string) error {
	aEntries, err := ioutil.ReadDir(name)
	if err != nil {
		return err
	}
	for _, f := range aEntries {
		if f.Name() == "." || f.Name() == ".." {
			continue
		}
		err = os.Remove(name + "/" + f.Name())
		if err != nil {
			return err
		}
	}
	return nil
}
1241169
func (fs *fakeFs) RemoveAll(path string) error {
	return fs.a.RemoveAll(path)
}
351774
func cleanAndExpandPath(path string) string {
	// NOTE: The os.ExpandEnv doesn't work with Windows cmd.exe-style
	// %VARIABLE%, but they variables can still be expanded via POSIX-style
	// $VARIABLE.
	path = os.ExpandEnv(path)

	if !strings.HasPrefix(path, "~") {
		return filepath.Clean(path)
	}

	// Expand initial ~ to the current user's home directory, or ~otheruser
	// to otheruser's home directory.  On Windows, both forward and backward
	// slashes can be used.
	path = path[1:]

	var pathSeparators string
	if runtime.GOOS == "windows" {
		pathSeparators = string(os.PathSeparator) + "/"
	} else {
		pathSeparators = string(os.PathSeparator)
	}

	userName := ""
	if i := strings.IndexAny(path, pathSeparators); i != -1 {
		userName = path[:i]
		path = path[i:]
	}

	homeDir := ""
	var u *user.User
	var err error
	if userName == "" {
		u, err = user.Current()
	} else {
		u, err = user.Lookup(userName)
	}
	if err == nil {
		homeDir = u.HomeDir
	}
	// Fallback to CWD if user lookup fails or user has no home directory.
	if homeDir == "" {
		homeDir = "."
	}

	return filepath.Join(homeDir, path)
}
326528
func (l Local) Delete(_ context.Context, path string) error {
	return os.RemoveAll(l.fullPath(path))
}
1277050
func (u *Updater) Cleanup(tmpDir string) {
	if tmpDir != "" {
		u.log.Debugf("Remove temporary directory: %q", tmpDir)
		if err := os.RemoveAll(tmpDir); err != nil {
			u.log.Warningf("Error removing temporary directory %q: %s", tmpDir, err)
		}
	}
}
24887
func (f *FilesystemStore) Remove(name string) error {
	p, err := f.getPath(name)
	if err != nil {
		return err
	}
	return os.RemoveAll(p) // RemoveAll succeeds if path doesn't exist
}
1072397
func RunDirPath(dirPath string, args ...string) error {
	return RunIODirPath(IO{}, dirPath, args...)
}
317865
func Remove(tempdir string) error {
	defer func() {
		var k string
		runningMutex.Lock()
		for key, value := range running {
			if value == tempdir {
				k = key
			}
		}
		delete(running, k)
		runningMutex.Unlock()
	}()
	if !strings.HasPrefix(tempdir, os.TempDir()) {
		return errors.New("Remove can only remove temporary directories, tryied to remove " + tempdir)
	}
	path := os.Getenv("PATH")
	index := strings.Index(path, tempdir)
	if index < 0 {
		return fmt.Errorf("%q is not in $PATH", tempdir)
	}
	path = path[:index] + path[index+len(tempdir)+1:]
	err := os.Setenv("PATH", path)
	if err != nil {
		return err
	}
	return os.RemoveAll(tempdir)
}
733859
func IsDir(path string) bool {
	f, err := os.Open(path)
	if err != nil {
		return false
	}
	defer func() {
		errutil.Trace(f.Close())
	}()

	fi, err := f.Stat()
	if err != nil {
		return false
	}

	return fi.Mode().IsDir()
}
601883
func IsDir(dir string) (bool, error) {
	_, err := os.Stat(filepath.Join(dir, defaultIndexFile))
	if os.IsNotExist(err) {
		return false, nil
	}
	return err == nil, err
}
1360716
func (c *Server) removeDeprecated(dirpath string) {
	if dirContents, err := ioutil.ReadDir(dirpath); !os.IsNotExist(err) {
		if err != nil {
			glog.Warningf("Could not look up deprecated exports path %s: %s", dirpath, err)
			return
		}

		// Unmount path
		if err := mp.Unmount(dirpath); err != nil {
			glog.Warningf("Could not unmount deprecated path %s: %s", dirpath, err)
		}

		// Guarantee the path is now empty
		if l := len(dirContents); l > 0 {
			glog.Warningf("Path %s is not empty.", dirpath)
		} else {
			// Remove the path only if it is empty
			if err := os.Remove(dirpath); err != nil {
				glog.Warningf("Could not remove deprecated path %s: %s", dirpath, err)
				return
			}
			glog.Infof("Deleted deprecated path %s", dirpath)
		}
	}
}
254498
func SplitPathDirEntry(path string) (dir, base string) {
	cleanedPath := filepath.Clean(normalizePath(path))

	if specifiesCurrentDir(path) {
		cleanedPath += string(filepath.Separator) + "."
	}

	return filepath.Dir(cleanedPath), filepath.Base(cleanedPath)
}
1022462
func (s *FileSystemStorage) Delete(filepath string) error {
	return os.Remove(s.Path(filepath))
}
441135
func (d *Dir) Remove(nodePath string, emptyOnly bool) error {
	var currentNode os.FileInfo = d
	if nodePath == "." || nodePath == "./" || nodePath == "" {
		return fmt.Errorf("memfs.Dir.Remove: It is not possible to delete myself")
	}
	pathNodes := strings.Split(path.Clean(nodePath), "/")
	lastDirNode := len(pathNodes) - 1
	for i := 0; i < lastDirNode; i++ {
		nodeName := pathNodes[i]
		if currentNode.IsDir() != true {
			return fmt.Errorf("memfs.Dir.Remove: Node by name %v must be dir to get sub node (path %v )", currentNode.Name(), nodePath)
		}
		var dir = currentNode.(*Dir)
		newNode, err := dir.GetNode(nodeName)
		if err != nil {
			return err
		}
		currentNode = newNode
	}
	if currentNode.IsDir() != true {
		return fmt.Errorf("memfs.Dir.Remove: Node by name %v must be dir to get sub node (path %v )", currentNode.Name(), nodePath)
	}
	currentDir := currentNode.(*Dir)
	removeNodeName := pathNodes[len(pathNodes)-1]
	for key, removedNode := range currentDir.nodes {
		if removedNode.Name() != removeNodeName {
			continue
		}
		if emptyOnly && removedNode.IsDir() {
			removedDir := removedNode.(*Dir)
			if len(removedDir.nodes) != 0 {
				return fmt.Errorf("memfs.Dir.Remove: Prevent remove no empty directory %v", nodePath)
			}
		}
		currentDir.nodes = append(currentDir.nodes[:key], currentDir.nodes[key+1:]...)
		return nil
	}
	return fmt.Errorf("memfs.Dir.Remove: Con not find node to remove (by name %v)", removeNodeName)
}
868223
func (fs *Filespace) Remove(subPath string) error {
	return os.Remove(fs.path + subPath)
}