Canonicalize after getting metadata. Canonicalizing follows symlinks

This commit is contained in:
Jon Moroney 2020-08-18 14:25:12 -07:00
parent 6fe847896e
commit 0d525abd56

View file

@ -54,6 +54,15 @@ pub fn deduplicate_dirs<P: AsRef<Path> + Sync>(search_dirs: Vec<P>) -> (Vec<File
}
fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPackage>) -> (){
let current_path_metadata = match fs::symlink_metadata(&current_path) {
Err(e) =>{
sender.send(
ChannelPackage::Fail(current_path.as_ref().to_path_buf(), e)
).expect("Error sending new ChannelPackage::Fail");
return
},
Ok(meta) => meta,
};
let current_path = match fs::canonicalize(&current_path) {
Err(e) => {
sender.send(
@ -61,17 +70,11 @@ fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPack
).expect("Error sending new ChannelPackage::Fail");
return
},
Ok(can_path) => can_path,
};
let current_path_metadata = match fs::symlink_metadata(&current_path) {
Err(e) =>{
sender.send(
ChannelPackage::Fail(current_path.to_path_buf(), e)
).expect("Error sending new ChannelPackage::Fail");
return
},
Ok(meta) => meta,
Ok(canonical_path) => canonical_path,
};
if !current_path_metadata.file_type().is_file() && !current_path_metadata.file_type().is_dir(){
println!("Operating on \n{:?}\n{:?}", current_path, current_path_metadata);
}
if current_path_metadata.file_type().is_symlink(){
sender.send(
ChannelPackage::Fail(current_path.to_path_buf(), Error::new(ErrorKind::Other, "Path is symlink"))