예제 #1
0
    def removedir(self, path, recursive=False, force=False):
        if normpath(path) in ('', '/'):
            raise RemoveRootError(path)

        affected_filesystems = [fs for fs in self if fs.exists(path)]

        if len(affected_filesystems) == 0:
            raise ResourceNotFoundError(path)

        for fs in affected_filesystems:
            fs.removedir(path, recursive=recursive, force=force)
예제 #2
0
	def remove(self, path):
		if path == '/':
			raise RemoveRootError()
		_CheckPath(path)
		with self._lock:
			info(f"remove: {path}")
			metadata = self._itemFromPath(path)
			if metadata is None:
				raise ResourceNotFound(path=path)
			if metadata["mimeType"] == _folderMimeType:
				raise FileExpected(path=path)
			self.drive.files().delete(fileId=metadata["id"]).execute(num_retries=self.retryCount)
예제 #3
0
	def removedir(self, path):
		if path == '/':
			raise RemoveRootError()
		_CheckPath(path)
		with self._lock:
			info(f"removedir: {path}")
			metadata = self._itemFromPath(path)
			if metadata is None:
				raise ResourceNotFound(path=path)
			if metadata["mimeType"] != _folderMimeType:
				raise DirectoryExpected(path=path)
			children = self._childrenById(metadata["id"])
			if len(children) > 0:
				raise DirectoryNotEmpty(path=path)
			self.drive.files().delete(fileId=metadata["id"]).execute(num_retries=self.retryCount)
예제 #4
0
 def remove(self, path):
     _log.info(f'remove({path})')
     path = self.validatepath(path)
     if path == '/':
         raise RemoveRootError()
     with self._lock:
         metadata = self._itemFromPath(path)
         if metadata is None:
             raise ResourceNotFound(path=path)
         if metadata['mimeType'] == _folderMimeType:
             raise FileExpected(path=path)
         self._drive.files().delete(
             fileId=metadata['id'],
             **self._file_kwargs,
         ).execute(num_retries=self.retryCount)
예제 #5
0
 def removedir(self, path):
     _log.info(f'removedir({path})')
     path = self.validatepath(path)
     if path == '/':
         raise RemoveRootError()
     with self._lock:
         metadata = self._itemFromPath(path)
         if metadata is None:
             raise ResourceNotFound(path=path)
         if metadata['mimeType'] != _folderMimeType:
             raise DirectoryExpected(path=path)
         children = self._childrenById(metadata['id'])
         if len(children) > 0:
             raise DirectoryNotEmpty(path=path)
         self._drive.files().delete(
             fileId=metadata['id'],
             **self._file_kwargs,
         ).execute(num_retries=self.retryCount)
예제 #6
0
파일: __init__.py 프로젝트: pombreda/fs-smb
    def removedir(self, path, recursive=False, force=False):
        if path == '/':
            raise RemoveRootError(path)

        # Remove directory tree from the bottom upwards depending upon the
        # flags.
        if force:
            for (del_dir, del_files) in self.walk(path,
                                                  search='depth',
                                                  ignore_errors=True):
                for f in del_files:
                    self.remove(pathjoin(del_dir, f))
                self.removedir(del_dir)
        elif recursive:
            paths = recursepath(path, reverse=True)[:-1]
            for p in paths:
                self._remove_dir(p)
        else:
            self._remove_dir(path)
예제 #7
0
def movedir(fs1,
            fs2,
            create_destination=True,
            ignore_errors=False,
            chunk_size=64 * 1024):
    """Moves contents of a directory from one filesystem to another.

    :param fs1: A tuple of (<filesystem>, <directory path>)
    :param fs2: Destination filesystem, or a tuple of (<filesystem>, <directory path>)
    :param create_destination: If True, the destination will be created if it doesn't exist    
    :param ignore_errors: If True, exceptions from file moves are ignored
    :param chunk_size: Size of chunks to move if a simple copy is used

    """
    if not isinstance(fs1, tuple):
        raise ValueError(
            "first argument must be a tuple of (<filesystem>, <path>)")

    fs1, dir1 = fs1
    parent_fs1 = fs1
    parent_dir1 = dir1
    fs1 = fs1.opendir(dir1)

    print fs1
    if parent_dir1 in ('', '/'):
        raise RemoveRootError(dir1)

    if isinstance(fs2, tuple):
        fs2, dir2 = fs2
        if create_destination:
            fs2.makedir(dir2, allow_recreate=True, recursive=True)
        fs2 = fs2.opendir(dir2)

    mount_fs = MountFS(auto_close=False)
    mount_fs.mount('src', fs1)
    mount_fs.mount('dst', fs2)

    mount_fs.copydir('src',
                     'dst',
                     overwrite=True,
                     ignore_errors=ignore_errors,
                     chunk_size=chunk_size)
    parent_fs1.removedir(parent_dir1, force=True)
예제 #8
0
    def removedir(self, path: str):
        """Remove empty directories from the filesystem.

        :param path: `str`: Directory to remove
        """
        dir_entry = self._get_dir_entry(path)
        try:
            base = dir_entry.get_parent_dir()
        except PyFATException as e:
            if e.errno == errno.ENOENT:
                # Don't remove root directory
                raise RemoveRootError(path)
            raise e

        # Verify if the directory is empty
        try:
            if not dir_entry.is_empty():
                raise DirectoryNotEmpty(path)
        except PyFATException as e:
            if e.errno == errno.ENOTDIR:
                raise DirectoryExpected(path)

        self._remove(base, dir_entry)
예제 #9
0
    def removedir(self, path, recursive=False, force=False):
        if self.isfile(path):
            raise ResourceInvalidError(path)
        if not self.isdir(path):
            if not self.isdir(dirname(path)):
                raise ParentDirectoryMissingError(path)
            raise ResourceNotFoundError(path)
        if abspath(path) == "/":
            raise RemoveRootError(path)
        if force:
            for child_path in self.listdir(path, full=True, dirs_only=True):
                self.removedir(child_path, force=force)
            for child_path in self.listdir(path, full=True, files_only=True):
                self.remove(child_path)
        elif len(self.listdir(path)) > 0:
            raise DirectoryNotEmptyError(path)

        self.client.auth.service.files() \
                                .delete(fileId=self._ids[path]) \
                                .execute()
        self._ids.pop(path)

        if recursive and len(self.listdir(dirname(path))) == 0:
            self.removedir(dirname(path), recursive=recursive)