[yabridgectl] Normalize symlinks for plugin counts

Now this should actually be correct with partially overlapping plugin
directories when symlinks were used.
This commit is contained in:
Robbert van der Helm
2021-07-05 17:51:06 +02:00
parent a06d0bc515
commit bf84057044
3 changed files with 33 additions and 6 deletions
+16
View File
@@ -176,6 +176,22 @@ pub fn hash_file(file: &Path) -> Result<i64> {
Ok(hasher.finish() as i64)
}
/// Resolve symlinks in a path, like the `realpath` coreutil, but don't throw any errors of `path`
/// does not exist, unlike the `realpath` libc function.
///
/// This is used to resolve symlinked directories in the syncing process so the plugin counts are
/// correct even when one plugin directory contains a symlink to another plugin directory.
pub fn normalize_path(path: &Path) -> PathBuf {
for prefix in path.ancestors() {
// If part of `path`s prefix exists, then we'll try to resolve symlinks there
if let Ok(normalized_prefix) = fs::canonicalize(&prefix) {
return normalized_prefix.join(path.strip_prefix(prefix).unwrap());
}
}
path.to_owned()
}
/// Verify that `yabridge-host.exe` can be found when yabridge is run in a host launched from the
/// GUI. We do this by launching a login shell, appending `~/.local/share/yabridge` to the login
/// shell's search path since that's what yabridge also does, and then making the the file can be