Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport: SshTransport bug in method rename #6725

Open
khsrali opened this issue Jan 23, 2025 · 3 comments · May be fixed by #6735
Open

Transport: SshTransport bug in method rename #6725

khsrali opened this issue Jan 23, 2025 · 3 comments · May be fixed by #6735
Labels
good first issue Issues that should be relatively easy to fix also for beginning contributors type/bug

Comments

@khsrali
Copy link
Contributor

khsrali commented Jan 23, 2025

There seems to be a bug in method rename of class SshTransport.

The code takes two arguments, old_path and new_path. Before renaming first, checks if the new_path does not exist it raises an OSError.

This seem to be a mistake.

    def rename(self, oldpath: TransportPath, newpath: TransportPath):
        """Rename a file or folder from oldpath to newpath.

        :param str oldpath: existing name of the file or folder
        :param str newpath: new name for the file or folder

        :raises OSError: if oldpath/newpath is not found
        :raises ValueError: if sroldpathc/newpath is not a valid path
        """
        if not oldpath:
            raise ValueError(f'Source {oldpath} is not a valid path')
        if not newpath:
            raise ValueError(f'Destination {newpath} is not a valid path')

        oldpath = str(oldpath)
        newpath = str(newpath)

        if not self.isfile(oldpath):
            if not self.isdir(oldpath):
                raise OSError(f'Source {oldpath} does not exist')

        if not self.isfile(newpath):
            if not self.isdir(newpath):
                raise OSError(f'Destination {newpath} does not exist')

        return self.sftp.rename(oldpath, newpath)
@khsrali khsrali added type/bug good first issue Issues that should be relatively easy to fix also for beginning contributors labels Jan 23, 2025
@ayushjariyal
Copy link

@khsrali Is this issue still open? I want to try this issue.

@khsrali
Copy link
Contributor Author

khsrali commented Jan 28, 2025

@ayushjariyal, yes it's open! go ahead and open a PR
Feel free to ping me, for a review :-)
Cheers!

@ayushjariyal ayushjariyal linked a pull request Jan 28, 2025 that will close this issue
@ayushjariyal
Copy link

@khsrali I have opened a PR. Could you please review it and let me know if any further improvements are needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that should be relatively easy to fix also for beginning contributors type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants