Fix broken symlinks not being removed

`Path::exists()` returns false for broken symlinks:

https://doc.rust-lang.org/std/path/struct.Path.html#method.exists
This commit is contained in:
Robbert van der Helm
2020-07-27 16:10:27 +02:00
parent 1113e43b03
commit 81696f4dde
2 changed files with 10 additions and 2 deletions
+4 -2
View File
@@ -18,6 +18,7 @@
use anyhow::{Context, Result};
use colored::Colorize;
use std::fs;
use std::path::{Path, PathBuf};
use crate::config::{Config, InstallationMethod};
@@ -173,9 +174,10 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
}
for plugin in search_results.vst2_files {
// If the target file already exists, we'll remove it first to prevent issues with
// mixing symlinks and regular files
// mixing symlinks and regular files. We check `std::fs::symlink_metadata` instead of
// `Path::exists()` because the latter reports false for broken symlinks.
let target_path = plugin.with_extension("so");
if target_path.exists() {
if fs::symlink_metadata(&target_path).is_ok() {
utils::remove_file(&target_path)?;
}