Do not overwrite unmanaged files in /etc.
This commit is contained in:
parent
f7edf3a52f
commit
4460250457
1 changed files with 15 additions and 3 deletions
|
|
@ -184,11 +184,23 @@ fn create_etc_static_link(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should we make sure that an existing file is managed before replacing it?
|
fn create_etc_link(
|
||||||
fn create_etc_link(link_target: &OsStr, etc_dir: &Path, state: EtcTree) -> (EtcTree, Result<()>) {
|
link_target: &OsStr,
|
||||||
|
etc_dir: &Path,
|
||||||
|
state: EtcTree,
|
||||||
|
old_state: &EtcTree,
|
||||||
|
) -> (EtcTree, Result<()>) {
|
||||||
let link_path = etc_dir.join(link_target);
|
let link_path = etc_dir.join(link_target);
|
||||||
let (new_state, status) = create_dir_recursively(link_path.parent().unwrap(), state);
|
let (new_state, status) = create_dir_recursively(link_path.parent().unwrap(), state);
|
||||||
match status.and_then(|_| {
|
match status.and_then(|_| {
|
||||||
|
if *old_state.get_status(&link_path) == EtcFileStatus::Unmanaged
|
||||||
|
&& (link_path.exists() || link_path.is_symlink())
|
||||||
|
{
|
||||||
|
anyhow::bail!(
|
||||||
|
"Unmanaged file {} already exists, ignoring...",
|
||||||
|
link_path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
create_link(
|
create_link(
|
||||||
&Path::new(".")
|
&Path::new(".")
|
||||||
.join(SYSTEM_MANAGER_STATIC_NAME)
|
.join(SYSTEM_MANAGER_STATIC_NAME)
|
||||||
|
|
@ -209,7 +221,7 @@ fn create_etc_entry(
|
||||||
) -> (EtcTree, Result<()>) {
|
) -> (EtcTree, Result<()>) {
|
||||||
if entry.mode == "symlink" {
|
if entry.mode == "symlink" {
|
||||||
if let Some(path::Component::Normal(link_target)) = entry.target.components().next() {
|
if let Some(path::Component::Normal(link_target)) = entry.target.components().next() {
|
||||||
create_etc_link(link_target, etc_dir, state)
|
create_etc_link(link_target, etc_dir, state, old_state)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
state,
|
state,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue