gardesk/garfield / 3289b39

Browse files

fix: Keep Both copies to unique path instead of renaming original

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
3289b390a73da61c1614fd090c594efc33673baf
Parents
8dc3328
Tree
e000f8d

3 changed files

StatusFile+-
M garfield/src/app.rs 2 21
M garfield/src/core/mod.rs 1 1
M garfield/src/core/operations.rs 8 4
garfield/src/app.rsmodified
@@ -98,8 +98,6 @@ struct PendingPaste {
9898
     dest_dir: PathBuf,
9999
     /// Files that conflict (exist in destination).
100100
     conflicts: Vec<PathBuf>,
101
-    /// Current conflict index being resolved.
102
-    current_conflict: usize,
103101
 }
104102
 
105103
 impl App {
@@ -1353,7 +1351,6 @@ impl App {
13531351
                     operation: op,
13541352
                     dest_dir,
13551353
                     conflicts,
1356
-                    current_conflict: 0,
13571354
                 });
13581355
                 return;
13591356
             }
@@ -1598,24 +1595,8 @@ impl App {
15981595
                 // Perform the copy/move with the unique name
15991596
                 let result = match pending.operation {
16001597
                     ClipboardOperation::Copy => {
1601
-                        if conflict_file.is_dir() {
1602
-                            // For directories, copy then rename to unique name
1603
-                            match garfield::core::copy_path(&conflict_file, &pending.dest_dir) {
1604
-                                Ok(copied_path) => {
1605
-                                    // Rename to unique name if different
1606
-                                    if copied_path != final_dest {
1607
-                                        std::fs::rename(&copied_path, &final_dest)
1608
-                                            .map(|_| final_dest.clone())
1609
-                                            .or(Ok(copied_path))
1610
-                                    } else {
1611
-                                        Ok(copied_path)
1612
-                                    }
1613
-                                }
1614
-                                Err(e) => Err(e),
1615
-                            }
1616
-                        } else {
1617
-                            std::fs::copy(&conflict_file, &final_dest).map(|_| final_dest.clone())
1618
-                        }
1598
+                        // Copy directly to the unique destination path
1599
+                        garfield::core::copy_to_path(&conflict_file, &final_dest)
16191600
                     }
16201601
                     ClipboardOperation::Cut => {
16211602
                         std::fs::rename(&conflict_file, &final_dest).map(|_| final_dest.clone())
garfield/src/core/mod.rsmodified
@@ -13,7 +13,7 @@ pub use entry::{
1313
 };
1414
 pub use history::History;
1515
 pub use operations::{
16
-    copy_files, copy_path, create_directory, delete_files, delete_path,
16
+    copy_files, copy_path, copy_to_path, create_directory, delete_files, delete_path,
1717
     make_unique_name, move_files, move_path, rename_path, OperationResult,
1818
 };
1919
 pub use trash::{empty_trash, restore_from_trash, trash_file, trash_files, trash_dir};
garfield/src/core/operations.rsmodified
@@ -53,20 +53,24 @@ impl OperationResult {
5353
     }
5454
 }
5555
 
56
-/// Copy a file or directory to a destination.
56
+/// Copy a file or directory to a destination directory (uses source filename).
5757
 pub fn copy_path(source: &Path, dest_dir: &Path) -> io::Result<PathBuf> {
5858
     let file_name = source.file_name().ok_or_else(|| {
5959
         io::Error::new(io::ErrorKind::InvalidInput, "Invalid source path")
6060
     })?;
6161
     let dest = dest_dir.join(file_name);
62
+    copy_to_path(source, &dest)
63
+}
6264
 
65
+/// Copy a file or directory to a specific destination path.
66
+pub fn copy_to_path(source: &Path, dest: &Path) -> io::Result<PathBuf> {
6367
     if source.is_dir() {
64
-        copy_dir_recursive(source, &dest)?;
68
+        copy_dir_recursive(source, dest)?;
6569
     } else {
66
-        fs::copy(source, &dest)?;
70
+        fs::copy(source, dest)?;
6771
     }
6872
 
69
-    Ok(dest)
73
+    Ok(dest.to_path_buf())
7074
 }
7175
 
7276
 /// Copy a directory recursively.