Skip to content

Commit

Permalink
Fix file_type check in rlink to ignore mode_t and just rely on file/d…
Browse files Browse the repository at this point in the history
…ir/symlink distinction
  • Loading branch information
wykurz committed Dec 3, 2023
1 parent 5551290 commit e851f01
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions common/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,14 @@ mod copy_tests {
}
}

// check if two files are identical
fn is_file_type_same(md1: &std::fs::Metadata, md2: &std::fs::Metadata) -> bool {
let ft1 = md1.file_type();
let ft2 = md2.file_type();
return ft1.is_dir() == ft2.is_dir()
&& ft1.is_file() == ft2.is_file()
&& ft1.is_symlink() == ft2.is_symlink();
}

fn is_unchanged(md1: &std::fs::Metadata, md2: &std::fs::Metadata) -> bool {
if md1.atime() != md2.atime()
|| md1.mtime() != md2.mtime()
Expand Down Expand Up @@ -534,7 +541,7 @@ pub async fn link(
};
if let Some(update_metadata) = update_metadata_opt.as_ref() {
let update = update.as_ref().unwrap();
if src_metadata.file_type() != update_metadata.file_type() {
if !is_file_type_same(&src_metadata, update_metadata) {
// file type changed, just copy the updated one
debug!(
"link: file type of {:?} ({:?}) and {:?} ({:?}) differs - copying from update",
Expand Down

0 comments on commit e851f01

Please sign in to comment.