Skip to content

fsspec.implementations.local.LocalFileSystem.mv doesn't respect auto_mkdir=True #1954

@cccs-malik

Description

@cccs-malik

The mv method of fsspec.implementations.local.LocalFileSystem doesn't seem to respect setting auto_mkdir to True. If you tell it to move a file to a directory that doesn't exist, it fails no matter the value of auto_mkdir.

From looking at the mv code, it looks like this could be resolved by simply adding a similar check to the one in cp_file at the start of the method.

Maybe something kind of like this:

    def mv(self, path1, path2, recursive: bool = True, **kwargs):
        """Move files/directories
        For the specific case of local, all ops on directories are recursive and
        the recursive= kwarg is ignored.
        """
        path1 = self._strip_protocol(path1)
        path2 = self._strip_protocol(path2)

        if self.auto_mkdir:
            self.makedirs(self._parent(path2), exist_ok=True)

        shutil.move(path1, path2)

Although, you might want to put some kind of extra check to prevent the creation of directories if path1 doesn't exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions