Просмотр исходного кода

fixing issues in copy while overwriting

vineethvk11 1 год назад
Родитель
Сommit
6006767a9f
2 измененных файлов с 19 добавлено и 4 удалено
  1. 7 2
      packages/backend/src/filesystem/hl_operations/hl_copy.js
  2. 12 2
      src/helpers.js

+ 7 - 2
packages/backend/src/filesystem/hl_operations/hl_copy.js

@@ -163,6 +163,7 @@ class HLCopy extends HLFilesystemOperation {
             throw APIError('cannot_copy_item_into_itself');
         }
 
+        let overwritten;
         if ( await dest.exists() ) {
             // condition: no overwrite behaviour specified
             if ( ! values.overwrite && ! values.dedupe_name ) {
@@ -189,12 +190,13 @@ class HLCopy extends HLFilesystemOperation {
                 dest = await parent.getChild(target_name);
             }
             else if ( values.overwrite ) {
-                if ( ! await chkperm(dest.entry, options.user.id, 'rm') ) {
+                if ( ! await chkperm(dest.entry, values.user.id, 'rm') ) {
                     throw APIError.create('forbidden');
                 }
 
                 // TODO: This will be LLRemove
                 // TODO: what to do with parent_operation?
+                overwritten = await dest.getSafeEntry();
                 const hl_remove = new HLRemove();
                 await hl_remove.run({
                     target: dest,
@@ -213,7 +215,10 @@ class HLCopy extends HLFilesystemOperation {
 
         await this.copied.awaitStableEntry();
         const response = await this.copied.getSafeEntry({ thumbnail: true });
-        return response;
+        return {
+            copied : response,
+            overwritten
+        };
     }
 }
 

+ 12 - 2
src/helpers.js

@@ -1579,8 +1579,13 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){
                             dedupeName: dest_path === path.dirname(copy_path),
                     });
 
+                    // remove overwritten item from the DOM
+                    if(resp[0].overwritten?.id){
+                        $(`.item[data-uid=${resp[0].overwritten.id}]`).removeItems();
+                    }
+
                     // copy new path for undo copy
-                    copied_item_paths.push(resp[0].path);
+                    copied_item_paths.push(resp[0].copied.path);
 
                     // skips next loop iteration
                     break;
@@ -1676,8 +1681,13 @@ window.copy_items = function(el_items, dest_path){
                             dedupeName: dest_path === path.dirname(copy_path),
                     })
 
+                    // remove overwritten item from the DOM
+                    if(resp[0].overwritten?.id){
+                        $(`.item[data-uid=${resp.overwritten.id}]`).removeItems();
+                    }
+
                     // copy new path for undo copy
-                    copied_item_paths.push(resp[0].path);
+                    copied_item_paths.push(resp[0].copied.path);
 
                     // skips next loop iteration
                     item_with_same_name_already_exists = false;