Ejemplo n.º 1
0
    def makedir(self, path, permissions=None, recreate=False):
        path = self.fix_path(path)
        if self.exists(path) and not recreate:
            raise errors.DirectoryExists(path)
        if path == "/":
            return SubFS(self, path)

        if self.exists(path):
            meta = self.getinfo(path)
            if meta.is_dir:
                if recreate == False:
                    raise errors.DirectoryExists(path)
                else:
                    return SubFS(self, path)
            if meta.is_file:
                raise errors.DirectoryExpected(path)

        ppath = self.get_parent(path)
        if not self.exists(ppath):

            raise errors.ResourceNotFound(ppath)

        try:

            folderMetadata = self.dropbox.files_create_folder_v2(path)
        except ApiError as e:

            raise errors.DirectoryExpected(path=path)

        return SubFS(self, path)
    def makedir(
            self,
            path,  # type: Text
            permissions=None,  # type: Optional[Permissions]
            recreate=False,  # type: bool
    ):
        # type: (...) -> SubFS[FS]
        """Make a directory.

        Arguments:
            path (str): Path to directory from root.
            permissions (~fs.permissions.Permissions, optional): a
                `Permissions` instance, or `None` to use default.
            recreate (bool): Set to `True` to avoid raising an error if
                the directory already exists (defaults to `False`).

        Returns:
            ~fs.subfs.SubFS: a filesystem whose root is the new directory.

        Raises:
            fs.errors.DirectoryExists: If the path already exists.
            fs.errors.ResourceNotFound: If the path is not found.

        """
        # mode = Permissions.get_mode(permissions)
        _path = self.validatepath(path)

        with self._lock:
            if _path == "/":
                if recreate:
                    return self.opendir(path)
                else:
                    raise errors.DirectoryExists(path)

            if _path.endswith("/"):
                _path = _path[:-1]
            dir_path, dir_name = split(_path)

            _dir_res = self._getresource(dir_path)
            if not _dir_res or not _dir_res.is_collection:
                raise errors.ResourceNotFound(path)

            if dir_name in _dir_res.get_member_names():
                if not recreate:
                    raise errors.DirectoryExists(path)

                _res = self._getresource(path)
                if _res and _res.is_collection:
                    return self.opendir(path)

            _dir_res.create_collection(dir_name)
            return self.opendir(path)
Ejemplo n.º 3
0
    def makedir(self,
                path: str,
                permissions: Optional[Permissions] = None,
                recreate: bool = False) -> SubFS[FS]:
        """Make a directory.

        Note:
            As GCS is not a real filesystem but a key-value store that does not have any concept of directories, we write empty blobs as a work around.
            See: https://fs-s3fs.readthedocs.io/en/latest/#limitations

            This implementation currently ignores the `permissions` argument, the empty blobs are written with default permissions.
        """
        self.check()
        _path = self.validatepath(path)
        _key = self._path_to_dir_key(_path)

        if not self.isdir(dirname(_path)):
            raise errors.ResourceNotFound(path)

        try:
            self.getinfo(path)
        except errors.ResourceNotFound:
            pass
        else:
            if recreate:
                return self.opendir(_path)
            else:
                raise errors.DirectoryExists(path)

        blob = self.bucket.blob(_key)
        blob.upload_from_string(b"")

        return SubFS(self, path)
Ejemplo n.º 4
0
    def makedir(self, path, permissions=None, recreate=False):
        _path = self.validatepath(path)

        if _path in '/':
            if not recreate:
                raise errors.DirectoryExists(path)

        elif not (recreate and self.isdir(path)):
            if self.exists(_path):
                raise errors.DirectoryExists(path)
            try:
                self.client.mkdir(_path.encode('utf-8'))
            except we.RemoteParentNotFound as exc:
                raise errors.ResourceNotFound(path, exc=exc)

        return self.opendir(path)
Ejemplo n.º 5
0
 def makedir(self, path, permissions=None, recreate=False):
     self.check()
     result = self.pcloud.createfolder(path=path)
     if result['result'] == 2004:
         raise errors.DirectoryExists('Directory "{0}" already exists')
     elif result['result'] != 0:
         raise errors.CreateFailed(
             'Create of directory "{0}" failed with "{1}"'.format(
                 path, result['error']))
     else:  # everything is OK
         return self.opendir(path)
Ejemplo n.º 6
0
 def makedir(self, path, permissions=None, recreate=False):
     self.check()
     result = self.pcloud.createfolder(path=path)
     if result["result"] == 2004:
         if recreate:
             # If the directory already exists and recreate = True
             # we don't want to raise an error
             pass
         else:
             raise errors.DirectoryExists(path)
     elif result["result"] != 0:
         raise errors.OperationFailed(path=path,
                                      msg='Create of directory failed with {0}'.format(result["error"]))
     else:  # everything is OK
         return self.opendir(path)
Ejemplo n.º 7
0
    def makedir(self, path, permissions=None, recreate=False):  # noqa: D102
        self.check()
        _permissions = permissions or Permissions(mode=0o755)
        _path = self.validatepath(path)

        try:
            info = self.getinfo(_path)
        except errors.ResourceNotFound:
            with self._lock:
                with convert_sshfs_errors('makedir', path):
                    self._sftp.mkdir(_path, _permissions.mode)
        else:
            if (info.is_dir and not recreate) or info.is_file:
                six.raise_from(errors.DirectoryExists(path), None)

        return self.opendir(path)
Ejemplo n.º 8
0
    def makedir(self, path, permissions=None, recreate=False):
        self.check()
        _path = self.validatepath(path)
        _key = self._path_to_dir_key(_path)

        if not self.isdir(dirname(_path.rstrip("/"))):
            raise errors.ResourceNotFound(path)

        try:
            self.getinfo(path)
        except errors.ResourceNotFound:
            pass
        else:
            if recreate:
                return self.opendir(_path)
            raise errors.DirectoryExists(path)
        with dlkerrors(path):
            self.dlk.mkdir(_key)
        return SubFS(self, _path)
Ejemplo n.º 9
0
Archivo: _s3fs.py Proyecto: miarec/s3fs
    def makedir(self, path, permissions=None, recreate=False):
        self.check()
        _path = self.validatepath(path)
        _key = self._path_to_dir_key(_path)

        if not self.isdir(dirname(_path)):
            raise errors.ResourceNotFound(path)

        try:
            self.getinfo(path)
        except errors.ResourceNotFound:
            pass
        else:
            if recreate:
                return self.opendir(_path)
            else:
                raise errors.DirectoryExists(path)
        with s3errors(path):
            self.s3.Object(self._bucket_name, _key).put()
        return self.opendir(path)
Ejemplo n.º 10
0
    def makedir(self, path: Text, permissions: Optional[Permissions] = None, recreate: bool = False) -> SubFS[FS]:
        """ Make a directory. """
        npath = self.normalize_path(path)
        if self.exists(npath):
            if recreate:
                return SubFS(self, npath)
            raise errors.DirectoryExists(path)
        if npath == "/":
            return SubFS(self, path)
        if not self.exists(dirname(npath)):
            raise errors.ResourceNotFound(dirname(path))

        perm = 0o750
        if permissions is not None:
            perm = permissions.mode

        cursor = self.connection.cursor()
        cursor.execute(
            "INSERT INTO sqlar (name, mode, mtime, sz, data) VALUES (?, ?, ?, ?, ?)",
            (npath, perm, datetime.utcnow().timestamp(), 0, None)
        )
        cursor.close()

        return SubFS(self, npath)