Mime: fallback to globs when globs2 is not available

This commit is contained in:
Pierre Pronchery 2022-05-01 00:49:58 +02:00
parent 48cd0b8aa8
commit 6fee9d8017

View File

@ -97,7 +97,16 @@ Mime * mime_new(GtkIconTheme * theme)
"/usr/pkg/share/mime/globs2", "/usr/pkg/share/mime/globs2",
NULL NULL
}; };
char ** g = globs2; char * globs[] =
{
DATADIR "/mime/globs",
"/usr/share/mime/globs",
"/usr/local/share/mime/globs",
"/usr/pkg/share/mime/globs",
NULL
};
int priority = 1;
char ** g;
FILE * fp = NULL; FILE * fp = NULL;
char buf[256]; char buf[256];
size_t len; size_t len;
@ -115,6 +124,10 @@ Mime * mime_new(GtkIconTheme * theme)
for(g = globs2; *g != NULL; g++) for(g = globs2; *g != NULL; g++)
if((fp = fopen(*g, "r")) != NULL) if((fp = fopen(*g, "r")) != NULL)
break; break;
if(fp == NULL)
for(g = globs, priority = 0; *g != NULL; g++)
if((fp = fopen(*g, "r")) != NULL)
break;
if(fp == NULL) if(fp == NULL)
{ {
error_set_code(1, "%s", "Could not load MIME globs"); error_set_code(1, "%s", "Could not load MIME globs");
@ -133,11 +146,16 @@ Mime * mime_new(GtkIconTheme * theme)
if(buf[0] == '#') if(buf[0] == '#')
continue; continue;
buf[len] = '\0'; buf[len] = '\0';
/* parse the priority */ if(priority)
errno = 0; {
strtoul(buf, &p, 0); /* parse the priority */
if(errno != 0 || *(p++) != ':') errno = 0;
continue; strtoul(buf, &p, 0);
if(errno != 0 || *(p++) != ':')
continue;
}
else
p = buf;
glob = strchr(p, ':'); glob = strchr(p, ':');
*(glob++) = '\0'; *(glob++) = '\0';
for(i = 0; i < mime->types_cnt; i++) for(i = 0; i < mime->types_cnt; i++)