Skip to content

Commit

Permalink
👌 SshTransport: Return FileNotFoundError if destination parent do…
Browse files Browse the repository at this point in the history
…es not exist

In 101a8d6 the engine was adapted to simply log
a warning in case a `FileNotFoundError` was raised by a remove copy operation. The logic
is that in case the source file does not exist this operation will fail every time.
Hence, it is not useful to trigger the exponential backoff mechanism and have this
operation fail multiple times.

However, when the parent folder of the target doesn't exist the remote copy command will
fail as well. In this case, the returned error was still an `OSError`, which is not
caught by the engine and logged as a warning. To obtain similar behaviour for these
two failures, we now parse the `stderr` returned by the `exec_command_wait_bytes`
method. In case it refers to a file or directory not being found, we raise a
`FileNoteFoundError` instead of a generic `OSError`.

Since this also deals with the case of a missing remote source file, we remove the check
in the `SshTransport.copy()` method.
  • Loading branch information
mbercx authored and sphuber committed Jun 4, 2024
1 parent a554517 commit d86bb38
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/aiida/transports/plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,6 @@ 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 All @@ -1188,6 +1185,9 @@ def _exec_cp(self, cp_exe, cp_flags, src, dst):
retval, stdout, stderr, command
)
)
if 'No such file or directory' in str(stderr):
raise FileNotFoundError(f'Error while executing cp: {stderr}')

raise OSError(
'Error while executing cp. Exit code: {}, ' "stdout: '{}', stderr: '{}', " "command: '{}'".format(
retval, stdout, stderr, command
Expand Down

0 comments on commit d86bb38

Please sign in to comment.