fixing issues in copy while overwriting

This commit is contained in:
vineethvk11
2024-04-05 09:11:39 +05:30
parent 35abf9a6bc
commit 6006767a9f
2 changed files with 19 additions and 4 deletions

View File

@@ -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
};
}
}

View File

@@ -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;