diff --git a/src/cli.rs b/src/cli.rs index b16e6f30..5d8ba7c7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -284,11 +284,7 @@ pub fn main() -> Result<()> { // Check if there is something at the destination path that needs to be // removed. - if path.exists() { - let meta = path - .symlink_metadata() - .into_diagnostic() - .wrap_err_with(|| format!("Failed to read metadata of path {:?}.", path))?; + if let Ok(meta) = path.symlink_metadata() { if !meta.file_type().is_symlink() { Warnings::SkippingPackageLink(pkg_name.clone(), path.clone()).emit(); continue; @@ -302,7 +298,7 @@ pub fn main() -> Result<()> { } // Create the symlink if there is nothing at the destination. - if !path.exists() { + if path.symlink_metadata().is_err() { if let Some(parent) = path.parent() { std::fs::create_dir_all(parent) .into_diagnostic() diff --git a/src/cmd/clone.rs b/src/cmd/clone.rs index 19a85afe..eff955c2 100644 --- a/src/cmd/clone.rs +++ b/src/cmd/clone.rs @@ -279,13 +279,7 @@ pub fn run(sess: &Session, path: &Path, args: &CloneArgs) -> Result<()> { // Check if there is something at the destination path that needs to be // removed. - if link_path.exists() { - let meta = link_path - .symlink_metadata() - .into_diagnostic() - .wrap_err_with(|| { - format!("Failed to read metadata of path {:?}.", link_path) - })?; + if let Ok(meta) = link_path.symlink_metadata() { if !meta.file_type().is_symlink() { Warnings::SkippingPackageLink(pkg_name.clone(), link_path.to_path_buf()).emit(); continue; @@ -299,7 +293,7 @@ pub fn run(sess: &Session, path: &Path, args: &CloneArgs) -> Result<()> { } // Create the symlink if there is nothing at the destination. - if !link_path.exists() { + if link_path.symlink_metadata().is_err() { if let Some(parent) = link_path.parent() { std::fs::create_dir_all(parent) .into_diagnostic() diff --git a/src/cmd/snapshot.rs b/src/cmd/snapshot.rs index 08debecd..ce3dd50a 100644 --- a/src/cmd/snapshot.rs +++ b/src/cmd/snapshot.rs @@ -248,13 +248,7 @@ pub fn run(sess: &Session, args: &SnapshotArgs) -> Result<()> { // Check if there is something at the destination path that needs to be // removed. - if link_path.exists() { - let meta = link_path - .symlink_metadata() - .into_diagnostic() - .wrap_err_with(|| { - format!("Failed to read metadata of path {:?}.", link_path) - })?; + if let Ok(meta) = link_path.symlink_metadata() { if !meta.file_type().is_symlink() { Warnings::SkippingPackageLink(pkg_name.clone(), link_path.to_path_buf()).emit(); continue; @@ -268,7 +262,7 @@ pub fn run(sess: &Session, args: &SnapshotArgs) -> Result<()> { } // Create the symlink if there is nothing at the destination. - if !link_path.exists() { + if link_path.symlink_metadata().is_err() { if let Some(parent) = link_path.parent() { std::fs::create_dir_all(parent) .into_diagnostic()