From 6006767a9ff0dcad500a07656f447dddcccd267f Mon Sep 17 00:00:00 2001 From: vineethvk11 Date: Fri, 5 Apr 2024 09:11:39 +0530 Subject: [PATCH] fixing issues in copy while overwriting --- .../src/filesystem/hl_operations/hl_copy.js | 9 +++++++-- src/helpers.js | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/filesystem/hl_operations/hl_copy.js b/packages/backend/src/filesystem/hl_operations/hl_copy.js index 98b81ac99..6c48550cd 100644 --- a/packages/backend/src/filesystem/hl_operations/hl_copy.js +++ b/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 + }; } } diff --git a/src/helpers.js b/src/helpers.js index 4d4f53cbf..47bf3741b 100644 --- a/src/helpers.js +++ b/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;