From f90abad0a77e14d044bc34d59fdf3ff207dbb91b Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 21 Feb 2026 14:33:31 +1300 Subject: 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. --- src/operations/cp.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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, destination_path: impl AsRef) - fn copy_file(source_path: impl AsRef, destination_path: impl AsRef) -> 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 { -- cgit v1.2.3-70-g09d2