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 solved #6750

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/aiida/transports/plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,16 +1368,13 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath):
oldpath = str(oldpath)
newpath = str(newpath)

if not self.isfile(oldpath):
if not self.isdir(oldpath):
raise OSError(f'Source {oldpath} does not exist')
# TODO: this seems to be a bug (?)
# why to raise an OSError if the newpath does not exist?
# ofcourse newpath shouldn't exist, that's why we are renaming it!
# issue opened here: https://github.com/aiidateam/aiida-core/issues/6725
if not self.isfile(newpath):
if not self.isdir(newpath):
raise OSError(f'Destination {newpath} does not exist')
"""The code now checks if oldpath exists and raises an OSError if not. A check is added to ensure that newpath doesn't already exist (using FileExistsError), to avoid unintentional overwriting."""

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

if self.isfile(newpath) or self.isdir(newpath):
raise FileExistsError(f'Destination {newpath}already exists')

return self.sftp.rename(oldpath, newpath)

Expand Down