Skip to content

Commit

Permalink
fix: Replacing existing symlinks now works (fixes #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
VorpalBlade committed Aug 17, 2024
1 parent 7f55bcd commit 8544f08
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/konfigkoll_core/src/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,21 @@ impl Applicator for InProcessApplicator {
}
}
FsOp::CreateSymlink { target } => {
std::os::unix::fs::symlink(target, &instr.path)
.context("Failed to create symlink")?;
match std::os::unix::fs::symlink(target, &instr.path) {
Ok(_) => Ok(()),
Err(err) => {
if err.kind() == std::io::ErrorKind::AlreadyExists {
// If the symlink already exists, we can just remove it and try
// again
std::fs::remove_file(&instr.path)
.context("Failed to remove old file before creating symlink")?;
std::os::unix::fs::symlink(target, &instr.path)
} else {
Err(err)
}
}
}
.context("Failed to create symlink")?
}
FsOp::CreateFifo => {
// Since we split out mode in general, we don't know what to put here.
Expand Down

0 comments on commit 8544f08

Please sign in to comment.