Skip to content

Commit ff9d236

Browse files
committed
update: do not try to copy a dir in the ESP if it does not exists
When doing removals, usually copy direcory to temp direcoty, then do operations in temp dir, but should check if the dir is existed in dest ESP. Fixes #856
1 parent 788e1ee commit ff9d236

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/filetree.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,11 @@ pub(crate) fn apply_diff(
339339
if first_dir != path {
340340
path_tmp = Utf8Path::new(&first_dir_tmp).join(path.strip_prefix(&first_dir)?);
341341
// copy to temp dir and remember
342-
if !destdir.exists(&first_dir_tmp)? {
343-
copy_dir(destdir, first_dir.as_str(), &first_dir_tmp)?;
342+
// skip copying if dir not existed in dest
343+
if !destdir.exists(&first_dir_tmp)? && destdir.exists(first_dir.as_std_path())? {
344+
copy_dir(destdir, first_dir.as_str(), &first_dir_tmp).with_context(|| {
345+
format!("copy {first_dir} to {first_dir_tmp} before removing {pathstr}")
346+
})?;
344347
updates.insert(first_dir, first_dir_tmp);
345348
}
346349
} else {
@@ -359,7 +362,9 @@ pub(crate) fn apply_diff(
359362
if first_dir != path {
360363
if !destdir.exists(&first_dir_tmp)? && destdir.exists(first_dir.as_std_path())? {
361364
// copy to temp dir if not exists
362-
copy_dir(destdir, first_dir.as_str(), &first_dir_tmp)?;
365+
copy_dir(destdir, first_dir.as_str(), &first_dir_tmp).with_context(|| {
366+
format!("copy {first_dir} to {first_dir_tmp} before updating {pathstr}")
367+
})?;
363368
}
364369
path_tmp = path_tmp.join(path.strip_prefix(&first_dir)?);
365370
// ensure new additions dir exists

0 commit comments

Comments
 (0)