datalad_ria.patches.sshremoteio

Correct flaws in SSHRemoteIO operation

The original code has a number of problems.

  1. The cmd-argument for the shell ssh-process, which is created by: self.shell = subprocess.Popen(cmd, ...) is not correct, if self.ssh``i is an instance of ``NoMultiplexSSHConnection.

    The changes in this patch build the correct cmd-argument by adding additional arguments to cmd, if self.ssh is an instance of NoMultiplexSSHConnection. More precisely, the arguments that are required to open a "shell" in a NoMultiplexSSHConnection are stored in NoMultiplexSSHConnection._ssh_open_args and not in NoMultiplexSSHConnection._ssh_args. This patch therefore provides arguments from both lists, i.e. from _ssh_args and _ssh_open_args in the call that opens a "shell", if self.ssh is an instance of NoMultiplexSSHConnection.

  2. The while-loop that waits to read b"RIA-REMOTE-LOGIN-END\n" from the shell ssh-process did not contain any error handling. That led to an infinite loop in case that the shell ssh-process terminates without writing b"RIA-REMOTE-LOGIN-END\n" to its stdout, or in the case that the stdout-pipeline of the shell ssh-process is closed.

    This patch introduces two checks into the while loop. One check for termination of the ssh shell-process, and one check for a closed stdout-pipeline of the ssh shell-process, i.e. reading an EOF from the stdout-pipeline. If any of those two cases appears, an exception is raised.

  3. The output endmarker handling in SSHRemoteIO._run() could not reliably handle commands that would yield output without a final newline (e.g., cat of a file without a trailing newline). This patch changes to endmarker handling to guarantee that they appear on a dedicated line, by prefixing the marker itself with a newline (which is withheld form the actual output).

  4. SSHRemoteIO.remove_dir() would not fail (unlike FileIO.remove_dir()) when ran on a non-empty directory. Despite not failing, it would also not remove that directory.

In addition, this patch modifies two comments. It adds a missing description of the buffer_size-parameter of SSHRemoteIO.__init__``to the doc-string, and fixes the description of the condition in the comment on the use of ``DEFAULT_BUFFER_SIZE.

datalad_ria.patches.sshremoteio.SSHRemoteIO__init__(self, host, buffer_size=65536)[source]
Parameters:
  • host (str) -- SSH-accessible host(name) to perform remote IO operations on.

  • buffer_size (int or None) -- The preferred buffer size

datalad_ria.patches.sshremoteio.SSHRemoteIO_append_end_markers(self, cmd)[source]

Append end markers to remote command

datalad_ria.patches.sshremoteio.SSHRemoteIO_remove_dir(self, path)[source]
datalad_ria.patches.sshremoteio.SSHRemoteIO_run(self, cmd, no_output=True, check=False)[source]
datalad_ria.patches.sshremoteio.patch(self, path)