Bug 454226

Summary: Pointless 'Undo: Copy" option is available in 'Edit' menu after skipping all files in a file operation
Product: [Frameworks and Libraries] frameworks-kio Reporter: Patrick Silva <bugseforuns>
Component: generalAssignee: KIO Bugs <kio-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: a.samirh78, kdelibs-bugs
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed In: 5.98

Description Patrick Silva 2022-05-22 17:47:04 UTC
STEPS TO REPRODUCE
1. copy two or more files to a folder
2. copy the same files to the same folder - 'File already exists' dialog shows up
3. check 'Apply to all' and click on 'Skip' button
4. if the menu bar of Dolphin is disabled, enabled it by pressing ctrl+m
5. open 'Edit' menu

OBSERVED RESULT
the first option is 'Undo: Copy' despite nothing was copied. All files were skipped in the step 3.
If I click on 'Undo: Copy', nothing happens.

EXPECTED RESULT
do not create 'Undo: Copy' when all files are skipped in a file operation

SOFTWARE/OS VERSIONS
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.25.80
KDE Frameworks Version: 5.95.0
Qt Version: 5.15.4
Graphics Platform: Wayland
Comment 1 Ahmad Samir 2022-07-11 17:39:47 UTC
Good catch!

https://invent.kde.org/frameworks/kio/-/merge_requests/908
Comment 2 Ahmad Samir 2022-08-19 15:54:56 UTC
Git commit c34f934e58911b0ab64fa9cdbbb662f69ab8dfda by Ahmad Samir.
Committed on 19/08/2022 at 15:35.
Pushed by ahmadsamir into branch 'master'.

FileUndoManager: for copyjob only add undo if it copied something

Test plan, before applying this patch:
- copy some files/dirs in dolphin, note the Edit menu now has an "undo copy"
  action
- copy the same files/dirs to the same destination again, you should see
  the copy conflict dialog
- enable "apply to all" and click "skip", nothing is copied; now check the
  Edit menu again, you should see the "undo copy" action still enabled,
  because another undo command was added even when nothing was copied
- trigger "undo copy", nothing happens
- trigger "undo copy" again, now it's asking if you want to delete
  /path/to/dest/files-you-copied-earlier from the destination

Add a unittest.
FIXED-IN: 5.98

M  +57   -0    autotests/fileundomanagertest.cpp
M  +1    -1    autotests/fileundomanagertest.h
M  +11   -0    src/widgets/fileundomanager.cpp

https://invent.kde.org/frameworks/kio/commit/c34f934e58911b0ab64fa9cdbbb662f69ab8dfda