Bug 506802 - Rename function leads to an error when target name is an existing directory
Summary: Rename function leads to an error when target name is an existing directory
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (other bugs)
Version First Reported In: 25.04.2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-09 14:11 UTC by Jan K
Modified: 2025-07-14 20:21 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan K 2025-07-09 14:11:59 UTC
SUMMARY

Using the Rename function to rename a file to such a name that happens to be an existing directory leads to loss of file contents.


STEPS TO REPRODUCE

1) In some directory, make a text file with any content and a subdirectory
2) Open the text file in Kate or Kwrite
3) Use File -> File actions -> Rename, enter the name of the existing subdirectory


OBSERVED RESULT

The editor tab is reopened with the new path, but the buffer is empty and an error is shown:

"The file <...> could not be loaded, as it was not possible to read from it.
Check if you have read access to this file."

The original file is gone, contents of the file are lost. Undo is not available.


EXPECTED RESULT

Show an error, keep the original file. The error message could explain the problem better.


SOFTWARE/OS VERSIONS

Application: Kate / KWrite 25.04.2
OS: Debian testing (trixie)
Filesystem: ext4
KDE Plasma Version: 6.3.5
KDE Frameworks Version: 6.13.0
Qt Version: 6.8.2
Comment 1 Waqar Ahmed 2025-07-14 12:39:50 UTC
There is no data loss, the file gets moved in the directory just.
Comment 2 Bug Janitor Service 2025-07-14 12:40:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1819
Comment 3 Jan K 2025-07-14 12:54:36 UTC
Thank you for looking into this. I apologize for my mistake, indeed the file is moved into the directory and not lost.

So the actual problem is that the moved file is not re-opened properly afterwards, instead giving an error. Moving could also be considered undesirable when the user only wanted to rename without realizing there is a directory, but this would be a minor issue.
Comment 4 Waqar Ahmed 2025-07-14 12:55:53 UTC
Indeed, the move is really unexpected. It makes sense if you think a bit deeper since renaming is just moving a file.
Comment 5 Christoph Cullmann 2025-07-14 18:23:28 UTC
Git commit 2e9f41b871d333bcdb7b0ef98a35d214e87263f0 by Christoph Cullmann, on behalf of Waqar Ahmed.
Committed on 14/07/2025 at 18:14.
Pushed by cullmann into branch 'master'.

Use KIO::moveAs to rename file

This will error out if there is an existing dir with the same name

M  +1    -1    apps/lib/katefileactions.cpp

https://invent.kde.org/utilities/kate/-/commit/2e9f41b871d333bcdb7b0ef98a35d214e87263f0
Comment 6 Christoph Cullmann 2025-07-14 20:21:29 UTC
Git commit 5e5238d29e7e0880c45df7ea1078baaa57ca530b by Christoph Cullmann.
Committed on 14/07/2025 at 20:21.
Pushed by cullmann into branch 'release/25.08'.

Use KIO::moveAs to rename file

This will error out if there is an existing dir with the same name


(cherry picked from commit 2e9f41b871d333bcdb7b0ef98a35d214e87263f0)

Co-authored-by: Waqar Ahmed <waqar.17a@gmail.com>

M  +1    -1    apps/lib/katefileactions.cpp

https://invent.kde.org/utilities/kate/-/commit/5e5238d29e7e0880c45df7ea1078baaa57ca530b