Skip to content

Commit

Permalink
Transports: Raise FileNotFoundError in copy if source doesn't exist
Browse files Browse the repository at this point in the history
The `LocalTransport` and `SshTransport` would raise a generic `OSError`
which would make it to distinguish the problem of the source not
existing from an more serious problem like the operation failing.
The methods now make sure to throw a `FileNotFoundError` if the source
doesn't exist.
  • Loading branch information
unkcpz authored and sphuber committed Jun 22, 2023
1 parent 49cffff commit d820694
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aiida/transports/plugins/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def copy(self, remotesource, remotedestination, dereference=False, recursive=Tru
raise ValueError('Input remotedestination to copy must be a non empty object')
if not self.has_magic(remotesource):
if not os.path.exists(os.path.join(self.curdir, remotesource)):
raise OSError('Source not found')
raise FileNotFoundError('Source not found')
if self.normalize(remotesource) == self.normalize(remotedestination):
raise ValueError('Cannot copy from itself to itself')

Expand Down
4 changes: 4 additions & 0 deletions aiida/transports/plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ def copy(self, remotesource, remotedestination, dereference=False, recursive=Tru
raise ValueError('Pathname patterns are not allowed in the destination')

if self.has_magic(remotesource):

to_copy_list = self.glob(remotesource)

if len(to_copy_list) > 1:
Expand All @@ -1213,6 +1214,9 @@ def copy(self, remotesource, remotedestination, dereference=False, recursive=Tru
self._exec_cp(cp_exe, cp_flags, file, remotedestination)

else:
if not self.path_exists(remotesource):
raise FileNotFoundError('Source not found')

self._exec_cp(cp_exe, cp_flags, remotesource, remotedestination)

def _exec_cp(self, cp_exe, cp_flags, src, dst):
Expand Down

0 comments on commit d820694

Please sign in to comment.