Skip to content

Commit eea100f

Browse files
Copilotprobonopd
andcommitted
Add support for metainfo.xml with symlink for backward compatibility
Co-authored-by: probonopd <[email protected]>
1 parent 0175b22 commit eea100f

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/appimagetool.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -857,18 +857,38 @@ main (int argc, char *argv[])
857857

858858
/* Check if AppStream upstream metadata is present in source AppDir */
859859
if(! no_appstream){
860-
char application_id[PATH_MAX];
861-
sprintf (application_id, "%s", basename(desktop_file));
862-
replacestr(application_id, ".desktop", ".appdata.xml");
863-
gchar *appdata_path = g_build_filename(source, "/usr/share/metainfo/", application_id, NULL);
864-
if (! g_file_test(appdata_path, G_FILE_TEST_IS_REGULAR)){
860+
char appdata_id[PATH_MAX];
861+
char metainfo_id[PATH_MAX];
862+
sprintf (appdata_id, "%s", basename(desktop_file));
863+
replacestr(appdata_id, ".desktop", ".appdata.xml");
864+
sprintf (metainfo_id, "%s", basename(desktop_file));
865+
replacestr(metainfo_id, ".desktop", ".metainfo.xml");
866+
gchar *appdata_path = g_build_filename(source, "/usr/share/metainfo/", appdata_id, NULL);
867+
gchar *metainfo_path = g_build_filename(source, "/usr/share/metainfo/", metainfo_id, NULL);
868+
gboolean appdata_exists = g_file_test(appdata_path, G_FILE_TEST_IS_REGULAR);
869+
gboolean metainfo_exists = g_file_test(metainfo_path, G_FILE_TEST_IS_REGULAR);
870+
871+
if (! appdata_exists && ! metainfo_exists){
865872
fprintf (stderr, "WARNING: AppStream upstream metadata is missing, please consider creating it\n");
866-
fprintf (stderr, " in usr/share/metainfo/%s\n", application_id);
873+
fprintf (stderr, " in usr/share/metainfo/%s\n", metainfo_id);
867874
fprintf (stderr, " Please see https://www.freedesktop.org/software/appstream/docs/chap-Quickstart.html#sect-Quickstart-DesktopApps\n");
868875
fprintf (stderr, " for more information or use the generator at\n");
869876
fprintf (stderr, " https://docs.appimage.org/packaging-guide/optional/appstream.html#using-the-appstream-generator\n");
870877
} else {
871-
fprintf (stderr, "AppStream upstream metadata found in usr/share/metainfo/%s\n", application_id);
878+
/* Create symlink if only one of the files exists, to ensure both paths work */
879+
if (appdata_exists && ! metainfo_exists) {
880+
fprintf (stderr, "Creating %s symlink to %s for compatibility\n", metainfo_id, appdata_id);
881+
int res = symlink(appdata_id, metainfo_path);
882+
if(res)
883+
fprintf (stderr, "WARNING: Could not create symlink %s\n", metainfo_path);
884+
} else if (metainfo_exists && ! appdata_exists) {
885+
fprintf (stderr, "Creating %s symlink to %s for compatibility\n", appdata_id, metainfo_id);
886+
int res = symlink(metainfo_id, appdata_path);
887+
if(res)
888+
fprintf (stderr, "WARNING: Could not create symlink %s\n", appdata_path);
889+
}
890+
891+
fprintf (stderr, "AppStream upstream metadata found in usr/share/metainfo/%s\n", (metainfo_exists ? metainfo_id : appdata_id));
872892
/* Use ximion's appstreamcli to make sure that desktop file and appdata match together */
873893
if(g_find_program_in_path ("appstreamcli")) {
874894
char *args[] = {
@@ -888,7 +908,7 @@ main (int argc, char *argv[])
888908
char *args[] = {
889909
"appstream-util",
890910
"validate-relax",
891-
appdata_path,
911+
(metainfo_exists ? metainfo_path : appdata_path),
892912
NULL
893913
};
894914
g_print("Trying to validate AppStream information with the appstream-util tool\n");

0 commit comments

Comments
 (0)