Bug 485551

Summary: Deleting a Kate session deletes the existing directory and files
Product: [Applications] kate Reporter: Yuta Tomino <demoonlit>
Component: sessionsAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: christoph, demoonlit, meven.car, meven29
Priority: NOR    
Version First Reported In: 23.08.3   
Target Milestone: ---   
Platform: Debian stable   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Yuta Tomino 2024-04-14 16:13:32 UTC
SUMMARY

Deleting a Kate session by Session Chooser deletes the existing directory and its files, if the session name matches the actual path.

I deleted one session in trying to make my Kate sessions correspond to the actual directories, and found that the directory had disappeared.
Fortunately, it was just after I took the backup.

STEPS TO REPRODUCE
1. Create new Kate session.
2. Save the session as a name that matches some existing path name starting with "/".
3. Delete the session from Kate's Session Chooser.

OBSERVED RESULT

The existing directory and its files are deleted.

EXPECTED RESULT

Only the *.katesession and stashed files in $HOME/.local/share/kate are deleted.

SOFTWARE/OS VERSIONS
Operating System: Devuan GNU/Linux 5 (daedalus)
Linux/KDE Plasma: 
KDE Plasma Version: 5.27.5
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.1.0-20-amd64 (64-bit)
Graphics Platform: X11

This is my guess, the cause is the below lines:
https://invent.kde.org/utilities/kate/-/blob/master/apps/lib/katestashmanager.cpp?ref_type=heads#L27
"sessionName" is not escaped here, so probably it tries to delete absolute path if "sessionName" contains "/".

Thanks.
Comment 1 Christoph Cullmann 2024-05-25 18:44:34 UTC
Hi, @meven, could you take a look? Thanks!
Comment 2 Méven Car 2024-05-28 09:58:32 UTC
> Fortunately, it was just after I took the backup.

Glad the impact was minimal.

> This is my guess, the cause is the below lines:
> https://invent.kde.org/utilities/kate/-/blob/master/apps/lib/katestashmanager.cpp?ref_type=heads#L27
> "sessionName" is not escaped here, so probably it tries to delete absolute path if "sessionName" contains "/".

This is correct analysis.

QDir::exists doc states:
``
Unless name contains an absolute file path, the file name is assumed to be relative to the directory itself, so this function is typically used to check for the presence of files within a directory.
```

`KateStashManager::stashDocuments` is also concerned.
You could see `Document 1` files in your session path for stashed files.
Comment 3 Bug Janitor Service 2024-06-01 09:34:03 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1510
Comment 4 Bug Janitor Service 2024-07-05 18:53:06 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1534
Comment 5 Christoph Cullmann 2024-07-09 16:38:47 UTC
Git commit 7e81ddf2604ec21b5934b6d27204e1e5fc6b9b17 by Christoph Cullmann.
Committed on 09/07/2024 at 16:27.
Pushed by cullmann into branch 'master'.

use session file name as stash folder name

that will we a proper directory name, all stuff is
percent encoded there

M  +14   -7    apps/lib/katestashmanager.cpp

https://invent.kde.org/utilities/kate/-/commit/7e81ddf2604ec21b5934b6d27204e1e5fc6b9b17