Skip to content

Commit 27d5e39

Browse files
authored
Merge pull request #858 from HuijingHei/check-dir
update: do not try to copy a dir in the ESP if it does not exists
2 parents 788e1ee + ff9d236 commit 27d5e39

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)