// RemoveDirectory removes the specified directory and all its contents
509146
func (h *fs) RemoveDirectory(dir string) error {
	glog.V(2).Infof("Removing directory '%s'", dir)

	// HACK: If deleting a directory in windows, call out to the system to do the deletion
	// TODO: Remove this workaround when we switch to go 1.7 -- os.RemoveAll should
	// be fixed for Windows in that release.  https://github.com/golang/go/issues/9606
	if runtime.GOOS == "windows" {
		command := exec.Command("cmd.exe", "/c", fmt.Sprintf("rd /s /q %s", dir))
		output, err := command.Output()
		if err != nil {
			glog.Errorf("Error removing directory %q: %v %s", dir, err, string(output))
			return err
		}
		return nil
	}

	err := os.RemoveAll(dir)
	if err != nil {
		glog.Errorf("Error removing directory '%s': %v", dir, err)
	}
	return err
}
411057
func (rd *RAMDirectory) DeleteFile(name string) error {
	rd.EnsureOpen()
	rd.fileMapLock.RLock()
	defer rd.fileMapLock.RUnlock()
	if file, ok := rd.fileMap[name]; ok {
		file.directory = nil
		atomic.AddInt64(&rd.sizeInBytes, -file.sizeInBytes)
		return nil
	}
	return errors.New(name)
}
1368807
func CreateDirectory(prefix string) (*Directory, error) {
	name, err := ioutil.TempDir("", prefix+"-")
	if err != nil {
		return nil, err
	}

	return &Directory{
		Name: name,
	}, nil
}
18491
func (c *Core) removeMountEntry(ctx context.Context, path string, updateStorage bool) error {
	c.mountsLock.Lock()
	defer c.mountsLock.Unlock()

	// Remove the entry from the mount table
	newTable := c.mounts.shallowClone()
	entry, err := newTable.remove(ctx, path)
	if err != nil {
		return err
	}
	if entry == nil {
		c.logger.Error("nil entry found removing entry in mounts table", "path", path)
		return logical.CodedError(500, "failed to remove entry in mounts table")
	}

	// When unmounting all entries the JSON code will load back up from storage
	// as a nil slice, which kills tests...just set it nil explicitly
	if len(newTable.Entries) == 0 {
		newTable.Entries = nil
	}

	if updateStorage {
		// Update the mount table
		if err := c.persistMounts(ctx, newTable, &entry.Local); err != nil {
			c.logger.Error("failed to remove entry from mounts table", "error", err)
			return logical.CodedError(500, "failed to remove entry from mounts table")
		}
	}

	c.mounts = newTable
	return nil
}
729538
func createDirectory(dir string, perms os.FileMode) error {
	// This prevents someone passing /path/to/dir and 'dir' not being created
	// If two '//' exist, MkdirAll deals it with correctly
	dir = dir + "/"
	return os.MkdirAll(dir, perms)
}
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)
}
958615
func (s *DirectoryClient) Delete(ctx context.Context, input *DeleteDirectoryInput) error {
	absPath := absFileInput(s.client.AccountName, input.DirectoryName)

	if input.ForceDelete {
		err := deleteAll(*s, ctx, absPath)
		if err != nil {
			return err
		}
	} else {
		err := deleteDirectory(*s, ctx, absPath)
		if err != nil {
			return err
		}
	}

	return nil
}
1308689
func removeFiles(dir string, fnames []string) error {
	for _, fname := range fnames {
		err := os.Remove(path.Join(dir, fname))
		if err != nil {
			return err
		}
	}

	return nil
}
782069
func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) (err error) {
	ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Remove",
		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 Remove %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 err
	}

	// node will be removed from Folder.nodes, if it is there in the
	// first place, by its Forget

	if req.Dir {
		err = d.folder.fs.config.KBFSOps().RemoveDir(ctx, d.node, req.Name)
	} else {
		err = d.folder.fs.config.KBFSOps().RemoveEntry(ctx, d.node, req.Name)
	}
	if err != nil {
		return err
	}

	return nil
}
626986
func (t *PackageList) RemoveByDir(dir string) {
	t.ensureInit()
	if pkg := t.LookupByDir(dir); pkg != nil {
		delete(t.pkgpool, pkg)
		delete(t.dirpool, pkg.Dir)
		delete(t.namepool, getPackageName(pkg))
	}
}
742795
func (d *Dir) CanDeleteDirectory(ctx context.Context, fi *dokan.FileInfo) (err error) {
	d.folder.fs.logEnterf(ctx, "Dir CanDeleteDirectory %q", d.name)
	defer func() { d.folder.reportErr(ctx, libkbfs.WriteMode, err) }()

	children, err := d.folder.fs.config.KBFSOps().GetDirChildren(ctx, d.node)
	if err != nil {
		return errToDokan(err)
	}
	if len(children) > 0 {
		return dokan.ErrDirectoryNotEmpty
	}

	return nil
}
1258942
func (s *UpdateUserInput) SetHomeDirectory(v string) *UpdateUserInput {
	s.HomeDirectory = &v
	return s
}
411519
func (s *Store) removeEmptyParentDirectories(path string) error {
	parent := filepath.Dir(path)

	if relpath, err := filepath.Rel(s.path, parent); err != nil {
		return err
	} else if strings.HasPrefix(relpath, ".") {
		return nil
	}

	err := os.Remove(parent)
	switch {
	case err == nil:
		return s.removeEmptyParentDirectories(parent)
	case err.(*os.PathError).Err == syscall.ENOTEMPTY:
		// ignore when directory is non-empty
		return nil
	default:
		return err
	}
}
808082
func (m *ManifestWriter) RemoveEntry(path string) error {
	m.trie.deleteEntry(path, m.quitC)
	return nil
}
577883
func (s *ListedUser) SetHomeDirectory(v string) *ListedUser {
	s.HomeDirectory = &v
	return s
}
377792
func (w *WebService) RemoveRoute(path, method string) error {
	if !w.dynamicRoutes {
		return errors.New("dynamic routes are not enabled.")
	}
	w.routesLock.Lock()
	defer w.routesLock.Unlock()
	newRoutes := make([]Route, (len(w.routes) - 1))
	current := 0
	for ix := range w.routes {
		if w.routes[ix].Method == method && w.routes[ix].Path == path {
			continue
		}
		newRoutes[current] = w.routes[ix]
		current = current + 1
	}
	w.routes = newRoutes
	return nil
}
868842
func (dd *DirData) RemoveEntry(ctx context.Context, name string) (
	unrefs []BlockInfo, err error) {
	topBlock, err := dd.GetTopBlock(ctx, BlockWrite)
	if err != nil {
		return nil, err
	}

	off := StringOffset(name)
	ptr, parentBlocks, block, _, _, _, err := dd.tree.getBlockAtOffset(
		ctx, topBlock, &off, BlockWrite)
	if err != nil {
		return nil, err
	}
	dblock := block.(*DirBlock)

	if _, exists := dblock.Children[name]; !exists {
		// Nothing to do.
		return nil, nil
	}
	delete(dblock.Children, name)

	// For now, just leave the block empty, at its current place in
	// the tree.  TODO: remove empty blocks all the way up the tree
	// and shift parent pointers around as needed.
	return dd.processModifiedBlock(ctx, ptr, parentBlocks, dblock)
}