mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
glocalfileinfo: Stop using PATH_MAX for .hidden
We were using PATH_MAX to size a static array for reading lines from the .hidden file. Some platforms (Hurd) don't declare a PATH_MAX. Switch to using g_file_get_contents() and g_str_split('\n') instead. Also take the time to clean up a bit with a switch to using a 'set mode' GHashTable (since this code was originally written before we had those). This patch is largely based on a patch from Emilio Pozuelo Monfort (who also reported the bug). https://bugzilla.gnome.org/show_bug.cgi?id=695147
This commit is contained in:
@@ -1437,35 +1437,30 @@ remove_from_hidden_cache (gpointer user_data)
|
|||||||
static GHashTable *
|
static GHashTable *
|
||||||
read_hidden_file (const gchar *dirname)
|
read_hidden_file (const gchar *dirname)
|
||||||
{
|
{
|
||||||
|
gchar *contents = NULL;
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
FILE *hidden;
|
|
||||||
|
|
||||||
filename = g_build_path ("/", dirname, ".hidden", NULL);
|
filename = g_build_path ("/", dirname, ".hidden", NULL);
|
||||||
hidden = fopen (filename, "r");
|
g_file_get_contents (filename, &contents, NULL, NULL);
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
|
|
||||||
if (hidden != NULL)
|
if (contents != NULL)
|
||||||
{
|
{
|
||||||
gchar buffer[PATH_MAX + 2]; /* \n\0 */
|
|
||||||
GHashTable *table;
|
GHashTable *table;
|
||||||
|
gchar **lines;
|
||||||
|
gint i;
|
||||||
|
|
||||||
table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||||
|
|
||||||
while (fgets (buffer, sizeof buffer, hidden))
|
lines = g_strsplit (contents, "\n", 0);
|
||||||
{
|
g_free (contents);
|
||||||
gchar *newline;
|
|
||||||
|
|
||||||
if ((newline = strchr (buffer, '\n')) != NULL)
|
for (i = 0; lines[i]; i++)
|
||||||
{
|
/* hash table takes the individual strings... */
|
||||||
*newline++ = '\0';
|
g_hash_table_add (table, lines[i]);
|
||||||
|
|
||||||
g_hash_table_insert (table,
|
/* ... so we only free the container. */
|
||||||
g_memdup (buffer, newline - buffer),
|
g_free (lines);
|
||||||
GINT_TO_POINTER (TRUE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (hidden);
|
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
@@ -1517,8 +1512,7 @@ file_is_hidden (const gchar *path,
|
|||||||
g_source_unref (remove_from_cache_source);
|
g_source_unref (remove_from_cache_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = table != NULL &&
|
result = table != NULL && g_hash_table_contains (table, basename);
|
||||||
GPOINTER_TO_INT (g_hash_table_lookup (table, basename));
|
|
||||||
|
|
||||||
G_UNLOCK (hidden_cache);
|
G_UNLOCK (hidden_cache);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user