[docker] docker cp correctly into container (#10253)

This commit is contained in:
Ian Rodney 2020-08-24 09:18:34 -07:00 committed by GitHub
parent 07f6cb17e4
commit f051c2852e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -617,6 +617,10 @@ class DockerCommandRunner(SSHCommandRunner):
f"mkdir -p {os.path.dirname(target.rstrip('/'))}")
self.ssh_command_runner.run_rsync_up(source, target)
if self._check_container_status():
if os.path.isdir(source):
# Adding a "." means that docker copies the *contents*
# Without it, docker copies the source *into* the target
target += "/."
self.ssh_command_runner.run("docker cp {} {}:{}".format(
target, self.docker_name,
self._docker_expand_user(protected_path)))
@ -627,6 +631,10 @@ class DockerCommandRunner(SSHCommandRunner):
source = source.replace("/root", "/tmp/root")
self.ssh_command_runner.run(
f"mkdir -p {os.path.dirname(source.rstrip('/'))}")
if protected_path[-1] == "/":
protected_path += "."
# Adding a "." means that docker copies the *contents*
# Without it, docker copies the source *into* the target
self.ssh_command_runner.run("docker cp {}:{} {}".format(
self.docker_name, self._docker_expand_user(protected_path),
source))