diff --git a/src/libaudcore/tuple.cc b/src/libaudcore/tuple.cc index d48304394..512f234e8 100644 --- a/src/libaudcore/tuple.cc +++ b/src/libaudcore/tuple.cc @@ -777,6 +777,28 @@ static StringBuf extract_domain(const char * start) return name; } +/* Sandboxed apps (Flatpak and Snap) receive granted files through the + * document portal as /run/user//doc//. is not the + * real directory that contains the file. */ +static bool is_document_portal_path(const char * path) +{ +#ifdef __linux__ + if (!path || strncmp(path, "/run/user/", 10)) + return false; + + const char * p = path + 10; + if (!g_ascii_isdigit(*p)) + return false; + + while (g_ascii_isdigit(*p)) + p++; + + return !strncmp(p, "/doc/", 5) || !strcmp(p, "/doc"); +#else + return false; +#endif +} + EXPORT void Tuple::generate_fallbacks() { if (!data) @@ -847,6 +869,11 @@ EXPORT void Tuple::generate_fallbacks() sep = G_DIR_SEPARATOR; } + // leave artist and album empty for sandboxed applications, + // the document portal hides the actual host filesystem path + if (is_document_portal_path(s)) + return; + StringBuf buf = str_copy(s); char * first = split_folder(buf, sep);