Bug 450727

Summary: Can't edit an application's desktop entry which is a symlink, because symlink copied instead of target file
Product: [Frameworks and Libraries] frameworks-kio Reporter: Roman Nikonov <code>
Component: Properties dialogAssignee: KIO Bugs <kio-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: alt, ashark, bizyaev, bugseforuns, cheery.idea2032, kdelibs-bugs, nate, stefan, tduck973564, twilightinzero, typingcat
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=394476
https://bugs.kde.org/show_bug.cgi?id=407552
Latest Commit: Version Fixed In: 5.96
Sentry Crash Report:
Attachments: Error when trying to change Discord's desktop entry

Description Roman Nikonov 2022-02-23 00:06:41 UTC
Created attachment 147067 [details]
Error when trying to change Discord's desktop entry

SUMMARY
If user tries to edit a desktop entry in /usr/share/applications that is a symlink to some file without write access, this results in an error.


STEPS TO REPRODUCE
1. Install a package that contains a symlink from /usr/share/applications. For example, Discord package on Arch/Manjaro: `pacman -S discord`
2. Open Application Launcher
3. Right-click on an app installed on step 1, select 'Edit application'
4. Change something and click 'Save'

OBSERVED RESULT
Error:
Could not save properties due to insufficient write access to:
‘/home/roma/.local/share/applications/discord.desktop’.

~/.local/share/applications/discord.desktop is a symlink to /opt/discord/discord.desktop.

EXPECTED RESULT
~/.local/share/applications/discord.desktop is successfully saved and is an arbitrary file owned by the current user.

SOFTWARE/OS VERSIONS
Linux distro: Manjaro stable
KDE Plasma Version: 5.23.5, master
KDE Frameworks Version: 5.90.0, master
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Similar bug: https://bugs.kde.org/show_bug.cgi?id=394476
But it needs to be resolved separately IMO, since it involves editing a file that's already in `~/.local/share/applications/` but is unwriteable for the current user.
Comment 1 Bug Janitor Service 2022-02-23 00:12:56 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/768
Comment 2 Bug Janitor Service 2022-05-22 11:51:33 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/848
Comment 3 Ahmad Samir 2022-06-13 19:19:43 UTC
Git commit a4be43231840a145c808f6ce81217f02f03935e8 by Ahmad Samir.
Committed on 13/06/2022 at 19:19.
Pushed by ahmadsamir into branch 'master'.

KPropertiesDialog: fix saving changes when editing a .desktop file symlink

Consider the use case of:
/usr/share/applications/foo.desktop is symlink to /opt/someapp/foo.desktop

relativeAppsLocation() was using QFile::canonicalFilePath(), which meant
that foo.desktop would resolve to a file outside /usr/share/applications,
since the code, rightly, expects files in QStandardPaths::ApplicationsLocation
locations, m_sRelativePath would end up being empty, which makes the check in
KFilePropsPlugin::slotCopyFinished() fail, and the .desktop file wouldn't
get copied to ~/.local/share/applications/, and the saving would fail.
FIXED-IN: 5.96

M  +5    -3    src/widgets/kpropertiesdialog.cpp

https://invent.kde.org/frameworks/kio/commit/a4be43231840a145c808f6ce81217f02f03935e8
Comment 4 Patrick Silva 2022-09-16 18:10:44 UTC
The error message persists on Arch Linux when I try to edit 'Name' field in 'Application' tab of 'Edit application' window of Discord icon present in Favorites list of Kickoff.

Operating System: Arch Linux
KDE Plasma Version: 5.25.90
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6
Graphics Platform: Wayland
Comment 5 gabe 2023-07-28 05:49:16 UTC
Still seeing this behavior on my machine, when editing any field. I'm particularly interested in adding to the "Environment Variables" field of Telegram flatpak

Operating System: Nobara Linux 38
KDE Plasma Version: 5.27.6
KDE Frameworks Version: 5.107.0
Qt Version: 5.15.10
Kernel Version: 6.3.12-204.fsync.fc38.x86_64 (64-bit)
Graphics Platform: X11
Processors: 12 × AMD Ryzen 5 3600X 6-Core Processor
Memory: 31.2 GiB of RAM
Graphics Processor: AMD Radeon RX 6700 XT
Manufacturer: ASUS
Comment 6 Andrew Shark 2023-10-25 13:05:02 UTC
*** Bug 451003 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Shark 2023-10-25 13:12:01 UTC
*** Bug 461941 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Shark 2023-10-25 13:27:12 UTC
The same happens with LibreOffice in Arch Linux.

The libreoffice-fresh package contains files:
/usr/lib/libreoffice/share/xdg/calc.desktop - the regular file
/usr/share/applications/libreoffice-calc.desktop - a simlink pointing to /usr/lib/libreoffice/share/xdg/calc.desktop

Now when I use "Edit Application" action, the file appears:
~/.local/share/applications/libreoffice-calc.desktop
but it is not a regular desktop file, instead, it is a symlink to the /usr/lib/libreoffice/share/xdg/calc.desktop

The utility should resolve symlinks, and copy the final desktop file, instead of literally copying the desktop file from /usr/share/applications (which could be a symlink).
Comment 9 Nate Graham 2024-05-14 23:24:35 UTC
*** Bug 486376 has been marked as a duplicate of this bug. ***