Skip to content

Commit 836cb9e

Browse files
committed
Fix updating of files using remote Docker.
This fixes copying files into a directory, where previously we copied the entire temp directory into the volume itself. This meant that `tmp.tmpLkX8M3` would be copied to `"${volume}/tmp.tmpLkX8M3"`, rather than its contents being copied into `"${volume}"`. This also ensures the updated fingerprint is written after all the files have been updated.
1 parent 801d5b5 commit 836cb9e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/docker/remote.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
9292
file::create_dir_all(dst_path.parent().expect("must have parent"))?;
9393
fs::copy(&src_path, &dst_path)?;
9494
}
95-
self.copy_files(temppath, dst, msg_info)
95+
// if copying from a src directory to dst directory with docker, to
96+
// copy the contents from `src` into `dst`, `src` must end with `/.`
97+
self.copy_files(&temppath.join("."), dst, msg_info)
9698
}
9799

98100
// removed files from a docker volume, for remote host support
@@ -351,15 +353,17 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
351353
// have stale data: the persistent volume was deleted & recreated.
352354
if fingerprint.exists() && self.container_path_exists(dst, msg_info)? {
353355
let previous = Fingerprint::read_file(&fingerprint)?;
354-
let (changed, removed) = previous.difference(&current);
355-
current.write_file(&fingerprint)?;
356-
357-
if !changed.is_empty() {
358-
self.copy_file_list(src, dst, &changed, msg_info)?;
356+
let (to_copy, to_remove) = previous.difference(&current);
357+
if !to_copy.is_empty() {
358+
self.copy_file_list(src, dst, &to_copy, msg_info)?;
359359
}
360-
if !removed.is_empty() {
361-
self.remove_file_list(dst, &removed, msg_info)?;
360+
if !to_remove.is_empty() {
361+
self.remove_file_list(dst, &to_remove, msg_info)?;
362362
}
363+
364+
// write fingerprint afterwards, in case any failure so we
365+
// ensure any changes will be made on subsequent runs
366+
current.write_file(&fingerprint)?;
363367
} else {
364368
current.write_file(&fingerprint)?;
365369
copy_all(msg_info)?;
@@ -530,22 +534,21 @@ impl Fingerprint {
530534
Ok(result)
531535
}
532536

533-
// gets difference between previous and current
537+
// returns to_copy (added + modified) and to_remove (removed).
534538
fn difference<'a, 'b>(&'a self, current: &'b Fingerprint) -> (Vec<&'b str>, Vec<&'a str>) {
535-
// this can be added or updated
536-
let changed: Vec<&str> = current
539+
let to_copy: Vec<&str> = current
537540
.map
538541
.iter()
539542
.filter(|(k, v1)| self.map.get(*k).map_or(true, |v2| v1 != &v2))
540543
.map(|(k, _)| k.as_str())
541544
.collect();
542-
let removed: Vec<&str> = self
545+
let to_remove: Vec<&str> = self
543546
.map
544547
.iter()
545548
.filter(|(k, _)| !current.map.contains_key(*k))
546549
.map(|(k, _)| k.as_str())
547550
.collect();
548-
(changed, removed)
551+
(to_copy, to_remove)
549552
}
550553
}
551554

0 commit comments

Comments
 (0)