Bug 482902 - Data loss on remote mount when using rmdir in terminal
Summary: Data loss on remote mount when using rmdir in terminal
Status: RESOLVED FIXED
Alias: None
Product: kiofuse
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Kubuntu Linux
: NOR critical
Target Milestone: ---
Assignee: Fabian Vogt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-08 18:04 UTC by Evan 'JabberWokky' Edwards
Modified: 2024-03-12 22:21 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Evan 'JabberWokky' Edwards 2024-03-08 18:04:04 UTC
I just lost a fair amount of data (luckily non-critical) because dolphin in 5.x (I checked three recent versions) behaves in the following manner:

1. If a remote directory is not explored, it appears empty within the filesystem (displaying 0 items in the panel)
2. If you then use `rmdir *` in the terminal to clear empty directories, leaving those that have files, the remote mounted filesystem has the same structure, so rmdir dutifully removes all directories including all files.

**Reproduction:**

This can be reproduced via this on the remote system (via ssh or some other "hidden from dolphin" method):

`mkdir -p $HOME/test/foo/bar ; echo MyData >$HOME/test/foo/bar/file.txt`

Then go to $HOME/test using sftp: url in dolphin, open the terminal and type `rmdir foo`

**Observed behavior:**

All data and files are removed from the mounted filesystem.

**Expected behavior:**

rmdir should see files inside the directory and not remove the directory.

---
I have not tested under KDE 6, but did test under a couple other 5.x Plasma desktops and observed the same behavior. 

[Administrivia note: I searched for this bug and the appropriate classification; I assume dolphin may be incorrect, but couldn't determine the correct classification.  Please reclassify to the correct software!]
Comment 1 Fabian Vogt 2024-03-08 21:00:40 UTC
I'm assuming you're using the sftp:// url in dolphin while the terminal sees the kio-fuse mount, e.g. /run/user/1000/kio-fuse....
Can you post a screenshot of such a situation for clarity?

> 1. If a remote directory is not explored, it appears empty within the filesystem (displaying 0 items in the panel)

Do you mean the terminal panel or the dolphin panel? It's intentional that directories are not populated unless necessary to avoid potentially slow network requests.

> 2. If you then use `rmdir *` in the terminal to clear empty directories, leaving those that have files, the remote mounted filesystem has the same structure, so rmdir dutifully removes all directories including all files.

rmdir is supposed to fail on nonempty directories, so the question is which layer is wrong here. kio-fuse translates the rmdir call on directories to KIO::del, unless it already knows that it has items. KIO::del appears to do a recursive deletion by default, which is wrong in this context. For directories, KIO::rmdir is probably more appropriate.
Comment 2 Bug Janitor Service 2024-03-08 21:31:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/kio-fuse/-/merge_requests/77
Comment 3 Nate Graham 2024-03-08 23:44:32 UTC
Data loss bugs are Critical; see https://community.kde.org/index.php?title=Guidelines_and_HOWTOs/Bug_triaging#Set_the_Severity_field

Resetting severity.
Comment 4 Evan 'JabberWokky' Edwards 2024-03-09 01:08:35 UTC
(In reply to Fabian Vogt from comment #1)
> I'm assuming you're using the sftp:// url in dolphin while the terminal sees
> the kio-fuse mount, e.g. /run/user/1000/kio-fuse....
> Can you post a screenshot of such a situation for clarity?

This is accurate.  I will post a screenshot shortly.


> > 1. If a remote directory is not explored, it appears empty within the filesystem (displaying 0 items in the panel)
> 
> Do you mean the terminal panel or the dolphin panel? It's intentional that
> directories are not populated unless necessary to avoid potentially slow
> network requests.

I mean the dolphin view of the filesystem -- the Details View Mode.  I realize now that I am assuming without evidence that it displaying "0 items" under size is related to the behavior in the terminal panel.  I have no direct reason to know that the two are related, and I completely understand why directory contents are not scanned until opened on remote filesystems.


> rmdir is supposed to fail on nonempty directories, so the question is which
> layer is wrong here. kio-fuse translates the rmdir call on directories to
> KIO::del, unless it already knows that it has items. KIO::del appears to do
> a recursive deletion by default, which is wrong in this context. For
> directories, KIO::rmdir is probably more appropriate.

This makes sense to me.  I do not know fuse (other than as a user), and I may have erroneously assumed the error was related to presenting a empty directory within the mount.

Thank you all for a prompt response; I've been using KDE since prior to the release of KDE 1.0, and I have always appreciated the work everybody has done and will do.  I will take screenshots and any other requested documentation in the next couple hours when I am able to do so.
Comment 5 Fabian Vogt 2024-03-12 22:21:45 UTC
Git commit 830f5cb4784a2e584bbfadeabe93410f0005205c by Fabian Vogt.
Committed on 08/03/2024 at 21:29.
Pushed by asaoutkin into branch 'master'.

Use KIO::rmdir for unlinking directories

Unlike KIO::del, this fails if the directory is not empty.

M  +5    -3    kiofusevfs.cpp
M  +22   -0    tests/fileopstest.cpp

https://invent.kde.org/system/kio-fuse/-/commit/830f5cb4784a2e584bbfadeabe93410f0005205c