+#ifndef G_OS_WIN32
+/* support for '.hidden' files */
+G_LOCK_DEFINE_STATIC (hidden_cache);
+static GHashTable *hidden_cache;
+
+static gboolean
+remove_from_hidden_cache (gpointer user_data)
+{
+ G_LOCK (hidden_cache);
+ g_hash_table_remove (hidden_cache, user_data);
+ G_UNLOCK (hidden_cache);
+
+ return FALSE;
+}
+
+static GHashTable *
+read_hidden_file (const gchar *dirname)
+{
+ gchar *contents = NULL;
+ gchar *filename;
+
+ filename = g_build_path ("/", dirname, ".hidden", NULL);
+ (void) g_file_get_contents (filename, &contents, NULL, NULL);
+ g_free (filename);
+
+ if (contents != NULL)
+ {
+ GHashTable *table;
+ gchar **lines;
+ gint i;
+
+ table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ lines = g_strsplit (contents, "\n", 0);
+ g_free (contents);
+
+ for (i = 0; lines[i]; i++)
+ /* hash table takes the individual strings... */
+ g_hash_table_add (table, lines[i]);
+
+ /* ... so we only free the container. */
+ g_free (lines);
+
+ return table;
+ }
+ else
+ return NULL;
+}
+
+static void
+maybe_unref_hash_table (gpointer data)
+{
+ if (data != NULL)
+ g_hash_table_unref (data);
+}
+
+static gboolean
+file_is_hidden (const gchar *path,
+ const gchar *basename)
+{
+ gboolean result;
+ gchar *dirname;
+ gpointer table;
+
+ dirname = g_path_get_dirname (path);
+
+ G_LOCK (hidden_cache);
+
+ if G_UNLIKELY (hidden_cache == NULL)
+ hidden_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, maybe_unref_hash_table);
+
+ if (!g_hash_table_lookup_extended (hidden_cache, dirname,
+ NULL, &table))
+ {
+ gchar *mydirname;
+ GSource *remove_from_cache_source;
+
+ g_hash_table_insert (hidden_cache,
+ mydirname = g_strdup (dirname),
+ table = read_hidden_file (dirname));
+
+ remove_from_cache_source = g_timeout_source_new_seconds (5);
+ g_source_set_priority (remove_from_cache_source, G_PRIORITY_DEFAULT);
+ g_source_set_callback (remove_from_cache_source,
+ remove_from_hidden_cache,
+ mydirname,
+ NULL);
+ g_source_attach (remove_from_cache_source,
+ GLIB_PRIVATE_CALL (g_get_worker_context) ());
+ g_source_unref (remove_from_cache_source);
+ }
+
+ result = table != NULL && g_hash_table_contains (table, basename);
+
+ G_UNLOCK (hidden_cache);
+
+ g_free (dirname);
+
+ return result;
+}
+#endif /* !G_OS_WIN32 */
+