Traverse the entire remote_path tree.

        Find files/directories that need to be deleted,
        not being present in the local folder.
335235
def check_for_deletion(self, relative_path=None):
        
        if not relative_path:
            relative_path = str()  # root of shared directory tree

        remote_path = path_join(self.remote_path, relative_path)
        local_path = path_join(self.local_path, relative_path)

        for remote_st in self.sftp.listdir_attr(remote_path):
            r_lstat = self.sftp.lstat(path_join(remote_path, remote_st.filename))

            inner_remote_path = path_join(remote_path, remote_st.filename)
            inner_local_path = path_join(local_path, remote_st.filename)

            # check if remote_st is a symlink
            # otherwise could delete file outside shared directory
            if S_ISLNK(r_lstat.st_mode):
                if self._must_be_deleted(inner_local_path, r_lstat):
                    self.remote_delete(inner_remote_path, r_lstat)
                continue

            if self._must_be_deleted(inner_local_path, remote_st):
                self.remote_delete(inner_remote_path, remote_st)
            elif S_ISDIR(remote_st.st_mode):
                self.check_for_deletion(
                    path_join(relative_path, remote_st.filename)
                )
195878
def search_paths(path = ENV['PATH'])
      paths = if path && !path.empty?
                path.split(::File::PATH_SEPARATOR)
              else
                %w(/usr/local/bin /usr/ucb /usr/bin /bin)
              end
      paths.select(&Dir.method(:exist?))
    end
1075168
def _walk_directory(root_directory):
        

        paths = [os.path.join(root, name)
                 for root, dirs, files in os.walk(root_directory)  # noqa
                 for name in files]
        paths.sort()
        return paths
173198
def remove_path(target_path):
    
    if os.path.isdir(target_path):
        shutil.rmtree(target_path)
    else:
        os.unlink(target_path)
750563
def remove_files():
    
    logger.info("Removing local track files that were not downloaded...")
    files = [f for f in os.listdir('.') if os.path.isfile(f)]
    for f in files:
        if f not in fileToKeep:
            os.remove(f)
138221
def remote_delete(self, remote_path, r_st):
        """"""
        # If it's a directory, then delete content and directory
        if S_ISDIR(r_st.st_mode):
            for item in self.sftp.listdir_attr(remote_path):
                full_path = path_join(remote_path, item.filename)
                self.remote_delete(full_path, item)
            self.sftp.rmdir(remote_path)

        # Or simply delete files
        else:
            try:
                self.sftp.remove(remote_path)
            except FileNotFoundError as e:
                self.logger.error(
                    "error while removing {}. trace: {}".format(remote_path, e)
                )
1034216
def remove_dirs(self, directory):
        

        LOG.info('Removing directory [ %s ]', directory)
        local_files = self._drectory_local_files(directory=directory)
        for file_name in local_files:
            try:
                os.remove(file_name['local_object'])
            except OSError as exp:
                LOG.error(str(exp))

        # Build a list of all local directories
        directories = sorted(
            [i for i, _, _ in os.walk(directory)],
            reverse=True
        )

        # Remove directories
        for directory_path in directories:
            try:
                os.removedirs(directory_path)
            except OSError as exp:
                if exp.errno != 2:
                    LOG.error(str(exp))
                pass
132096
def get_empty_dirs(self, path):
        """"""
        empty_dirs = []
        for i in os.listdir(path):
            child_path = os.path.join(path, i)
            if i == '.git' or os.path.isfile(child_path) or os.path.islink(child_path):  # noqa
                continue
            if self.path_only_contains_dirs(child_path):
                empty_dirs.append(i)
        return empty_dirs
309742
def find_file_paths(self):
        
        paths = []
        for root, dirs, files in os.walk(self.directory, topdown=True):
            rel_path = os.path.relpath(root, self.directory)
            for f in files:
                if rel_path == '.':
                    path = (f, os.path.join(root, f))
                else:
                    path = (os.path.join(rel_path, f), os.path.join(root, f))
                paths.append(path)
        return paths
635252
def cleanup(self):
        """"""
        for path in self.paths:
            if isinstance(path, tuple):
                os.close(path[0])
                os.unlink(path[1])
            else:
                shutil.rmtree(path)
        self.paths = []
1057283
def remove_directories(list_of_paths):
    
    found_dirs = set('/')
    for path in list_of_paths:
        dirs = path.strip().split('/')
        for i in range(2,len(dirs)):
            found_dirs.add( '/'.join(dirs[:i]) )

    paths = [ path for path in list_of_paths if
              (path.strip() not in found_dirs) and path.strip()[-1]!='/' ]
    return paths
664842
def _clear_old_remotes():
    '''
    
    '''
    bp_ = os.path.join(__opts__['cachedir'], 'svnfs')
    try:
        cachedir_ls = os.listdir(bp_)
    except OSError:
        cachedir_ls = []
    repos = init()
    # Remove actively-used remotes from list
    for repo in repos:
        try:
            cachedir_ls.remove(repo['hash'])
        except ValueError:
            pass
    to_remove = []
    for item in cachedir_ls:
        if item in ('hash', 'refs'):
            continue
        path = os.path.join(bp_, item)
        if os.path.isdir(path):
            to_remove.append(path)
    failed = []
    if to_remove:
        for rdir in to_remove:
            try:
                shutil.rmtree(rdir)
            except OSError as exc:
                log.error(
                    'Unable to remove old svnfs remote cachedir %s: %s',
                    rdir, exc
                )
                failed.append(rdir)
            else:
                log.debug('svnfs removed old cachedir %s', rdir)
    for fdir in failed:
        to_remove.remove(fdir)
    return bool(to_remove), repos
75985
def recursive_pattern_delete(root, file_patterns, directory_patterns, dry_run=False):
    """"""
    for root, dirs, files in os.walk(root):
        for pattern in file_patterns:
            for file_name in fnmatch.filter(files, pattern):
                file_path = os.path.join(root, file_name)
                if dry_run:
                    print_('Removing {}'.format(file_path))
                    continue
                os.remove(file_path)

        for pattern in directory_patterns:
            for found_dir in fnmatch.filter(dirs, pattern):
                if os.path.exists(found_dir):
                    if dry_run:
                        print('Removing directory tree {}'.format(found_dir))
                        continue
                    shutil.rmtree(found_dir)
694567
def safe_remove(path):
    
    if not os.path.exists(path):
        return

    try:
        if os.path.isdir(path) and not os.path.islink(path):
            shutil.rmtree(path)
        else:
            os.remove(path)
    except OSError:
        if os.path.exists(path):
            raise
757371
def remove(self, remote_path):
        
        # Based on the remote file stats; remove a file or directory recursively
        ftp = self.ssh.open_sftp()
        if stat.S_ISDIR(ftp.stat(remote_path).st_mode):
            self.__remove_dir(ftp, remote_path)
        else:
            ftp.remove(remote_path)
        ftp.close()
1029349
def filter_dirs(root, dirs, excl_paths):
    
    filtered_dirs = []
    for dirpath in dirs:
        abspath = os.path.abspath(os.path.join(root, dirpath))
        if os.path.basename(abspath) in _SKIP_DIRS:
            continue
        if abspath not in excl_paths:
            filtered_dirs.append(dirpath)
    return filtered_dirs
1339710
def _catalog_local_files_for_deletion(self):
        # type: (Downloader) -> None
        
        if not (self._spec.options.delete_extraneous_destination and
                self._spec.destination.is_dir):
            return
        dst = str(self._spec.destination.path)
        for file in blobxfer.util.scantree(dst):
            self._delete_after.add(pathlib.Path(file.path))