glib:gio fails to generate DesktopAppInfos (returns NULL pointer) for valid desktop files
Here is a straightforward reproducer with source code. Note the invalid behavior first, and in the second quote (with the trimmed desktop file) the valid behavior.
(please adjust the path of the appinfo2
line in the sample code to correspond to the sample desktop files I'm pasting below.)
Invalid behavior with correct desktop file:
[user@disp9884 ~]$ cat dai.c ; echo --------------- ; cat .local/share/applications/org.kde.kate.desktop ; echo -------------- ; gcc dai.c -o dai `pkg-config --cflags --libs gio-unix-2.0` && ./dai ; echo --------------
#include <stdio.h>
#include <gio/gdesktopappinfo.h>
int main() {
void * appinfo = g_desktop_app_info_new_from_filename ("/home/user/.local/share/applications/org.kde.kate.desktop");
printf("Pointer: %d\n", appinfo);
void * appinfo2 = g_desktop_app_info_new_from_filename ("/usr/share/applications/org.kde.kate.desktop");
printf("Pointer: %d\n", appinfo2);
}
---------------
[Desktop Action Session d4c143f004d88b7286e6f999dea9d0d7]
Exec=kate -s accounting
Name=accounting
[Desktop Entry]
Actions=Session d4c143f004d88b7286e6f999dea9d0d7;
Categories=Qt;KDE;Utility;TextEditor;
Comment=KDE Advanced Text Editor
Exec=kate -b %U
GenericName=Advanced Text Editor
Icon=kate
InitialPreference=9
MimeType=text/plain;
Name=Kate
StartupNotify=true
Terminal=false
Type=Application
X-DBUS-ServiceName=org.kde.kate
X-DBUS-StartupType=Multi
X-DocPath=kate/index.html
X-KDE-HasTempFileOption=true
--------------
Pointer: 0
Pointer: 23308608
--------------
Valid behavior with trimmed desktop file (absent the [Desktop action]
section):
[user@disp9884 ~]$ cat dai.c ; echo --------------- ; cat .local/share/applications/org.kde.kate.desktop ; echo -------------- ; gcc dai.c -o dai `pkg-config --cflags --libs gio-unix-2.0` && ./dai ; echo --------------
#include <stdio.h>
#include <gio/gdesktopappinfo.h>
int main() {
void * appinfo = g_desktop_app_info_new_from_filename ("/home/user/.local/share/applications/org.kde.kate.desktop");
printf("Pointer: %d\n", appinfo);
void * appinfo2 = g_desktop_app_info_new_from_filename ("/usr/share/applications/org.kde.kate.desktop");
printf("Pointer: %d\n", appinfo2);
}
---------------
[Desktop Entry]
Actions=Session d4c143f004d88b7286e6f999dea9d0d7;
Categories=Qt;KDE;Utility;TextEditor;
Comment=KDE Advanced Text Editor
Exec=kate -b %U
GenericName=Advanced Text Editor
Icon=kate
InitialPreference=9
MimeType=text/plain;
Name=Kate
StartupNotify=true
Terminal=false
Type=Application
X-DBUS-ServiceName=org.kde.kate
X-DBUS-StartupType=Multi
X-DocPath=kate/index.html
X-KDE-HasTempFileOption=true
--------------
Pointer: 22866032
Pointer: 22866240
--------------
This is a bug in the stable version of GIO as distributed by Fedora:
[user@disp9884 ~]$ rpm -qf /usr/include/glib-2.0/gio/gio.h
glib2-devel-2.60.7-2.fc30.x86_64
This is a Fedora 30 box.
The problem can also be reproduced on a Fedora 31 box:
[root@roxanne ~]# rpm -qf /usr/include/glib-2.0/gio/gio.h
glib2-devel-2.62.3-1.fc31.x86_64
So the problem has been there for a while.
I'm upstreaming this from https://github.com/QubesOS/qubes-issues/issues/5559
Thanks for your attention.