From 5666e727880b43f30a8115a6acadf90a04c9912d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 10 Feb 2023 19:06:47 +0100 Subject: [PATCH] Copy `.cargo` and `.xargo` correctly Co-authored-by: josh-bpl <124796608+josh-bpl@users.noreply.github.com> --- src/docker/remote.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/docker/remote.rs b/src/docker/remote.rs index 5db8c153c..3d131bfca 100644 --- a/src/docker/remote.rs +++ b/src/docker/remote.rs @@ -67,6 +67,16 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> { mount_prefix: &str, msg_info: &mut MessageInfo, ) -> Result { + if let Some((_, rel)) = reldst.rsplit_once('/') { + if src.is_dir() && src.file_name().unwrap().to_utf8()? == rel { + eyre::bail!( + "reldst is pointing to the wrong path: {} -> {}\n{}", + src.as_posix_relative()?, + reldst, + std::panic::Location::caller() + ); + } + } subcommand_or_exit(self.engine, "cp")? .arg("-a") .arg(src.to_utf8()?) @@ -196,7 +206,15 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> { mount_prefix, msg_info, )?; - self.copy_files(dirs.xargo(), &reldst, mount_prefix, msg_info)?; + self.copy_files( + dirs.xargo(), + reldst + .rsplit_once('/') + .ok_or_else(|| eyre::eyre!("cargo can't be a root directory"))? + .0, + mount_prefix, + msg_info, + )?; } Ok(()) @@ -216,7 +234,15 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> { .unwrap_or(copy_registry); if copy_registry { - self.copy_files(dirs.cargo(), &reldst, mount_prefix, msg_info)?; + self.copy_files( + dirs.cargo(), + reldst + .rsplit_once('/') + .ok_or_else(|| eyre::eyre!("cargo can't be a root directory"))? + .0, + mount_prefix, + msg_info, + )?; } else { // can copy a limit subset of files: the rest is present. self.create_dir(&reldst, mount_prefix, msg_info)?;