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 {

View file

@ -71,7 +71,13 @@ forEachUbuntuImage
node1.wait_for_unit("default.target")
node1.succeed("/system-manager-profile/bin/activate")
node1.succeed("touch /etc/foo_test")
node1.succeed("/system-manager-profile/bin/activate 2>&1 | tee /tmp/output.log")
node1.succeed("grep -F 'Error while creating file in /etc: Unmanaged path already exists in filesystem, please remove it and run system-manager again: /etc/foo_test' /tmp/output.log")
node1.succeed("rm /etc/foo_test")
node1.succeed("/system-manager-profile/bin/activate 2>&1 | tee /tmp/output.log")
node1.succeed("grep -vF 'ERROR' /tmp/output.log")
node1.wait_for_unit("system-manager.target")
node1.wait_for_unit("service-9.service")
@ -81,7 +87,8 @@ forEachUbuntuImage
node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
node1.succeed("${newConfig}/bin/activate")
node1.succeed("${newConfig}/bin/activate 2>&1 | tee /tmp/output.log")
node1.succeed("grep -vF 'ERROR' /tmp/output.log")
node1.wait_for_unit("new-service.service")
node1.wait_until_fails("systemctl status service-9.service")
node1.wait_until_fails("cat /etc/a/nested/example/foo3")
@ -145,7 +152,8 @@ forEachUbuntuImage
node1.wait_for_unit("default.target")
node1.succeed("/system-manager-profile/bin/prepopulate")
node1.succeed("/system-manager-profile/bin/prepopulate 2>&1 | tee /tmp/output.log")
node1.succeed("grep -vF 'ERROR' /tmp/output.log")
node1.systemctl("daemon-reload")
node1.systemctl("start default.target")
node1.wait_for_unit("system-manager.target")
@ -157,7 +165,8 @@ forEachUbuntuImage
node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
node1.succeed("${newConfig}/bin/activate")
node1.succeed("${newConfig}/bin/activate 2>&1 | tee /tmp/output.log")
node1.succeed("grep -vF 'ERROR' /tmp/output.log")
node1.wait_for_unit("new-service.service")
node1.wait_until_fails("systemctl status service-9.service")
node1.wait_until_fails("cat /etc/a/nested/example/foo3")