Bug 497390

Summary: Moving a trashed file to the trash and undoing makes the file disappear
Product: [Frameworks and Libraries] frameworks-kio Reporter: kde.aerospace405
Component: TrashAssignee: KIO Bugs <kio-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: akselmo, kdelibs-bugs, kfm-devel
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description kde.aerospace405 2024-12-12 20:47:33 UTC
SUMMARY
Files in trash disappear after moving file in trash to trash and undoing.

STEPS TO REPRODUCE
1. Send a file (filename.txt) to the trash.
2. Open trash in dolphin.
3. Hold shift and drag to an empty space inside the trash folder
4. File gets renamed to filename (1).txt
5. Press CTRL+Z
6. The files are gone!


OBSERVED RESULT
File is gone.

EXPECTED RESULT
File doesn't disappear.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora Linux 41
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.0

ADDITIONAL INFORMATION
Comment 1 kde.aerospace405 2024-12-12 20:49:10 UTC
Quick note: the files are still in ~/.local/share/Trash, but you can't view them in the "Trash" folder.
Comment 2 Akseli Lahtinen 2024-12-16 09:46:39 UTC
Can confirm. Dragging the file when its inside trash folder causes something odd to happen. Super weird!

dolphin 25.03.70
Operating System: Fedora Linux 41
KDE Plasma Version: 6.2.80
KDE Frameworks Version: 6.10.0
Qt Version: 6.8.1
Kernel Version: 6.12.4-200.fc41.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 3600 6-Core Processor
Memory: 15,5 GiB of RAM
Graphics Processor: AMD Radeon RX 6600
Comment 3 Akseli Lahtinen 2025-01-14 11:37:49 UTC
Did some more investigation on this. This happens because of `kio/src/widgets/dropjob.cpp:485`
The problem is that when dragging a file inside trash:// folder, the `allItemsAreFromTrash` boolean doesn't stay true, because the filepath is not `trash://file.txt` but `file://~/.local/share/Trash/files/file.txt`. Both are same thing essentially, just different protocol.

Moving this under KIO.
Comment 4 Bug Janitor Service 2025-01-14 12:27:13 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1782
Comment 5 Akseli Lahtinen 2025-01-14 13:48:52 UTC
To add my own steps, very similar to the reporter

1. Send file to trash
2. Open trash folder in dolphin
3. Drag the file inside trash folder to any empty space inside the trash view
4. File gets renamed and weird
Comment 6 Méven 2025-01-16 20:30:56 UTC
Git commit 98a77e4905ea1d7a0cdf427bc1cc254a5d971c5a by Méven Car, on behalf of Akseli Lahtinen.
Committed on 16/01/2025 at 20:30.
Pushed by meven into branch 'master'.

dropjob: Check if file is already in trash during dropjob

Previously we checked if file is already in trash during the dropjob,
but only by using the scheme. We should also check using the xdg path,
to make sure we are not moving the same file to same folder, causing it
to rename and confusing users.

This also adds unittest `shouldDropFromXdgTrashToTrash`.

M  +30   -0    autotests/dropjobtest.cpp
M  +18   -0    src/widgets/dropjob.cpp

https://invent.kde.org/frameworks/kio/-/commit/98a77e4905ea1d7a0cdf427bc1cc254a5d971c5a