Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Feb 11, 2023
1 parent 0994a23 commit a3fa4f9
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
.run_and_get_status(msg_info, false)
}

// copy files for a docker volume, for remote host support
// NOTE: `reldst` has the same caveats as `reldir` in `create_dir`.
/// Copy files for a docker volume
///
/// `reldst` has the same caveats as `reldir` in [`Self::create_dir`].
///
/// ## Note
///
/// if copying from a src directory to dst directory with docker, to
/// copy the contents from `src` into `dst`, `src` must end with `/.`
#[track_caller]
fn copy_files(
&self,
Expand All @@ -68,13 +74,17 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
msg_info: &mut MessageInfo,
) -> Result<ExitStatus> {
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{}",
if msg_info.cross_debug
&& src.is_dir()
&& !src.to_string_lossy().ends_with("/.")
&& rel == src.file_name().unwrap()
{
msg_info.warn(format_args!(
"source is pointing to a directory instead of its contents: {} -> {}\nThis might be a bug. {}",
src.as_posix_relative()?,
reldst,
std::panic::Location::caller()
);
))?;
}
}
subcommand_or_exit(self.engine, "cp")?
Expand All @@ -84,7 +94,12 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
.run_and_get_status(msg_info, false)
}

// copy files for a docker volume, for remote host support
/// copy files for a docker volume, does not include cache directories
///
/// ## Note
///
/// if copying from a src directory to dst directory with docker, to
/// copy the contents from `src` into `dst`, `src` must end with `/.`
#[track_caller]
fn copy_files_nocache(
&self,
Expand Down Expand Up @@ -124,8 +139,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
file::create_dir_all(dst_path.parent().expect("must have parent"))?;
fs::copy(src_path, &dst_path)?;
}
// if copying from a src directory to dst directory with docker, to
// copy the contents from `src` into `dst`, `src` must end with `/.`

self.copy_files(&temppath.join("."), reldst, mount_prefix, msg_info)
}

Expand Down Expand Up @@ -206,15 +220,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
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,
)?;
self.copy_files(&dirs.xargo().join("."), &reldst, mount_prefix, msg_info)?;
}

Ok(())
Expand All @@ -234,15 +240,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
.unwrap_or(copy_registry);

if copy_registry {
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,
)?;
self.copy_files(&dirs.cargo().join("."), &reldst, mount_prefix, msg_info)?;
} else {
// can copy a limit subset of files: the rest is present.
self.create_dir(&reldst, mount_prefix, msg_info)?;
Expand Down Expand Up @@ -406,9 +404,9 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
) -> Result<()> {
let copy_all = |info: &mut MessageInfo| {
if copy_cache {
self.copy_files(src, reldst, mount_prefix, info)
self.copy_files(&src.join("."), reldst, mount_prefix, info)
} else {
self.copy_files_nocache(src, reldst, mount_prefix, true, info)
self.copy_files_nocache(&src.join("."), reldst, mount_prefix, true, info)
}
};
match volume {
Expand Down

0 comments on commit a3fa4f9

Please sign in to comment.