Repository navigation
Fix relative paths in ParamikoSSHClient.put() and putfo() - #2261
Open
abedalawieh wants to merge 1 commit into
Open
abedalawieh wants to merge 1 commit into
abedalawieh wants to merge 1 commit into
Conversation
Since the SFTP client is reused between calls, put() and putfo()
starting a relative path with sftp.chdir(".") resolved it against the
directory the previous call changed to rather than the home directory.
For example, SSHKeyDeployment after a FileDeployment to
/etc/app/app.cfg wrote /etc/app/.ssh/authorized_keys.
Relative paths with a directory were also broken: putfo() changed into
the directory and then uploaded to the full relative path, which failed,
and both methods returned the directory twice in the file's path.
ScriptDeployment then joined the directory onto that path again, so a
script with such a name couldn't be run.
Reset the SFTP working directory before a relative upload, take the
base directory before descending into the path's directories, upload to
the file name in putfo(), and let ScriptDeployment use the full path
that put() returns.
abedalawieh
force-pushed
the
fix/sftp-cwd-between-uploads
branch
from
December 6, 2026 02:38
7eca0ac to
6733f1c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix relative paths in ParamikoSSHClient.put() and putfo()
Description
Since #1483,
ParamikoSSHClientreuses one SFTP client for everyput()/putfo()call. Both methods start a relative path withsftp.chdir(".")("start from a home directory"), but on a reused client"."is whatever directory the previous call changed into, so relative paths were resolved against the wrong directory.deploy_node()runs all deployment steps over one client, so this shows up with ordinary deployments.Checked against a real sshd (paramiko 5.0.0), trunk vs this PR:
MultiStepDeployment([FileDeployment(src, "/etc/myapp/app.cfg"), SSHKeyDeployment(key)])/etc/myapp/.ssh/authorized_keys~/.ssh/authorized_keysput("sub1/a.txt")/root/sub1/sub1/a.txt/root/sub1/a.txtputfo("b.txt")(after the above)/root/sub1/b.txt/root/b.txtputfo("sub2/d.txt"),FileDeployment(src, "conf/app.cfg")FileNotFoundError~ScriptDeployment(script, name="scripts/run.sh")/root/scripts/scripts/scripts/run.sh: No such fileChanges:
put()/putfo(): for a relative path, callsftp.chdir(None)(paramiko's reset to the server's default directory) beforesftp.chdir("."), and read the base directory before descending into the path's directories, so the returned path no longer repeats them.putfo(): upload to the file name, since it has already changed into the target directory (it uploaded to the full relative path before, which only worked without a directory).ScriptDeployment.run(): for a relativename, use the full path thatput()returns (asBaseSSHClient.put()documents) instead of joiningdirname(file_path)andnameagain. For names without a directory the result is the same; this also avoids theos.path.jointhat closed PR fix linux command deployment when running libcloud on windows #1602 was about.Tests:
test_put_and_putfo_relative_path_in_subdirectoryuses a small fake SFTP client that tracks the working directory like paramiko does,test_script_deployment_relative_path_in_subdirectorycoversScriptDeployment, and the existing relative-path tests now also check the reset. The new tests fail on trunk and pass with this change; all tests inlibcloud/test/computepass.This, #2259 and #2260 all add an entry at the top of the Compute section of
CHANGES.rst, so the later ones will need a trivial rebase.Status
Checklist (tick everything that applies)