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 {
98
     dest_dir: PathBuf,
98
     dest_dir: PathBuf,
99
     /// Files that conflict (exist in destination).
99
     /// Files that conflict (exist in destination).
100
     conflicts: Vec<PathBuf>,
100
     conflicts: Vec<PathBuf>,
101
-    /// Current conflict index being resolved.
102
-    current_conflict: usize,
103
 }
101
 }
104
 
102
 
105
 impl App {
103
 impl App {
@@ -1353,7 +1351,6 @@ impl App {
1353
                     operation: op,
1351
                     operation: op,
1354
                     dest_dir,
1352
                     dest_dir,
1355
                     conflicts,
1353
                     conflicts,
1356
-                    current_conflict: 0,
1357
                 });
1354
                 });
1358
                 return;
1355
                 return;
1359
             }
1356
             }
@@ -1598,24 +1595,8 @@ impl App {
1598
                 // Perform the copy/move with the unique name
1595
                 // Perform the copy/move with the unique name
1599
                 let result = match pending.operation {
1596
                 let result = match pending.operation {
1600
                     ClipboardOperation::Copy => {
1597
                     ClipboardOperation::Copy => {
1601
-                        if conflict_file.is_dir() {
1598
+                        // Copy directly to the unique destination path
1602
-                            // For directories, copy then rename to unique name
1599
+                        garfield::core::copy_to_path(&conflict_file, &final_dest)
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
-                        }
1619
                     }
1600
                     }
1620
                     ClipboardOperation::Cut => {
1601
                     ClipboardOperation::Cut => {
1621
                         std::fs::rename(&conflict_file, &final_dest).map(|_| final_dest.clone())
1602
                         std::fs::rename(&conflict_file, &final_dest).map(|_| final_dest.clone())
garfield/src/core/mod.rsmodified
@@ -13,7 +13,7 @@ pub use entry::{
13
 };
13
 };
14
 pub use history::History;
14
 pub use history::History;
15
 pub use operations::{
15
 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,
17
     make_unique_name, move_files, move_path, rename_path, OperationResult,
17
     make_unique_name, move_files, move_path, rename_path, OperationResult,
18
 };
18
 };
19
 pub use trash::{empty_trash, restore_from_trash, trash_file, trash_files, trash_dir};
19
 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 {
53
     }
53
     }
54
 }
54
 }
55
 
55
 
56
-/// Copy a file or directory to a destination.
56
+/// Copy a file or directory to a destination directory (uses source filename).
57
 pub fn copy_path(source: &Path, dest_dir: &Path) -> io::Result<PathBuf> {
57
 pub fn copy_path(source: &Path, dest_dir: &Path) -> io::Result<PathBuf> {
58
     let file_name = source.file_name().ok_or_else(|| {
58
     let file_name = source.file_name().ok_or_else(|| {
59
         io::Error::new(io::ErrorKind::InvalidInput, "Invalid source path")
59
         io::Error::new(io::ErrorKind::InvalidInput, "Invalid source path")
60
     })?;
60
     })?;
61
     let dest = dest_dir.join(file_name);
61
     let dest = dest_dir.join(file_name);
62
+    copy_to_path(source, &dest)
63
+}
62
 
64
 
65
+/// Copy a file or directory to a specific destination path.
66
+pub fn copy_to_path(source: &Path, dest: &Path) -> io::Result<PathBuf> {
63
     if source.is_dir() {
67
     if source.is_dir() {
64
-        copy_dir_recursive(source, &dest)?;
68
+        copy_dir_recursive(source, dest)?;
65
     } else {
69
     } else {
66
-        fs::copy(source, &dest)?;
70
+        fs::copy(source, dest)?;
67
     }
71
     }
68
 
72
 
69
-    Ok(dest)
73
+    Ok(dest.to_path_buf())
70
 }
74
 }
71
 
75
 
72
 /// Copy a directory recursively.
76
 /// Copy a directory recursively.