summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2026-02-21 14:33:31 +1300
committerBen Bridle <ben@derelict.engineering>2026-02-21 14:33:31 +1300
commitf90abad0a77e14d044bc34d59fdf3ff207dbb91b (patch)
treec38bdf6ea8b1997945c80b6b97cfaef681d31321
parent87f8a866f75f86d39684119fbba4538922efbb6d (diff)
downloadvagabond-f90abad0a77e14d044bc34d59fdf3ff207dbb91b.zip
Allow copying a file over the top of a symbolic link
When a symbolic link exists at the destination path when copying a file, the symbolic link has to be manually deleted first else the copy will fail.
-rw-r--r--src/operations/cp.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/operations/cp.rs b/src/operations/cp.rs
index 6037b67..1e5ab2e 100644
--- a/src/operations/cp.rs
+++ b/src/operations/cp.rs
@@ -45,6 +45,12 @@ pub fn copy(source_path: impl AsRef<Path>, destination_path: impl AsRef<Path>) -
fn copy_file(source_path: impl AsRef<Path>, destination_path: impl AsRef<Path>) -> WriteResult<()> {
// Only copy file if size or last modified time is different to file at destination.
if let Comparison::Different(last_modified) = compare_files(&source_path, &destination_path) {
+ // If existing file is a symlink, delete the link first else the copy will fail.
+ if let Ok(metadata) = destination_path.as_ref().symlink_metadata() {
+ if metadata.is_symlink() {
+ let _ = remove_file(&destination_path);
+ }
+ };
let copy_result = std::fs::copy(&source_path, &destination_path);
io_result_to_write_result(copy_result, &destination_path.as_ref())?;
if let Some(time) = last_modified {