Properly handle already existing but unmanaged files.

This commit is contained in:
r-vdp 2023-05-16 16:51:23 +02:00
parent 7e78522c02
commit 77077427dd
No known key found for this signature in database
2 changed files with 19 additions and 5 deletions

View file

@ -295,9 +295,14 @@ where
{
log::debug!("Link {} up to date.", link_path.display());
Ok(dir_state.register_managed_entry(&link_path))
} else if link_path.exists() && !old_state.is_managed(&link_path) {
Err(ActivationError::with_partial_result(
dir_state,
anyhow::anyhow!("Unmanaged path already exists in filesystem, please remove it and run system-manager again: {}",
link_path.display()),
))
} else {
let result = if link_path.exists() {
assert!(old_state.is_managed(&link_path));
fs::remove_file(&link_path)
.map_err(|e| ActivationError::with_partial_result(dir_state.clone(), e))
} else {