client: NameHolder: cleanup published symlink on drop

This commit is contained in:
Wez Furlong committed 2022-01-06 22:35:25 -07:00
1 parent 17a9d6159a
commit ec94bc989b
1 file changed
+20 -2
+20 -2
View File
@@ -251,7 +251,22 @@ mod windows {
mod unix {
use super::*;
pub struct NameHolder {}
pub struct NameHolder {
published: PathBuf,
name: PathBuf,
}
impl Drop for NameHolder {
fn drop(&mut self) {
// If it still points to us, remove the symlink
if let Ok(target) = std::fs::read_link(&self.name) {
if target == self.published {
log::trace!("removing {}", self.name.display());
std::fs::remove_file(&self.name).ok();
}
}
}
}
impl NameHolder {
fn compute_name(class_name: &str) -> String {
@@ -286,7 +301,10 @@ mod unix {
std::fs::remove_file(&name).ok();
std::os::unix::fs::symlink(path, &name)
.with_context(|| format!("pointing {} -> {}", name.display(), path.display()))?;
Ok(Self {})
Ok(Self {
published: path.to_path_buf(),
name,
})
}
pub fn resolve(class_name: &str) -> anyhow::Result<PathBuf> {