fileinfo: mark lost+found/ root directory as hidden
authorDavid Zeuthen <zeuthen@gmail.com>
Thu, 6 Dec 2012 21:21:58 +0000 (16:21 -0500)
committerDavid Zeuthen <zeuthen@gmail.com>
Thu, 6 Dec 2012 21:21:58 +0000 (16:21 -0500)
This was reported in bug 689800.

https://bugzilla.gnome.org/show_bug.cgi?id=689800

Signed-off-by: David Zeuthen <zeuthen@gmail.com>
gio/glocalfile.c
gio/glocalfileinfo.c
gio/glocalfileinfo.h

index ae60870..db4a48a 100644 (file)
@@ -1806,6 +1806,46 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
   return res;
 }
 
+#ifdef G_OS_UNIX
+gboolean
+_g_local_file_is_lost_found_dir (const char *path, dev_t path_dev)
+{
+  gboolean ret = FALSE;
+  gchar *mount_dir = NULL;
+  size_t mount_dir_len;
+  GStatBuf statbuf;
+
+  if (!g_str_has_suffix (path, "/lost+found"))
+    goto out;
+
+  mount_dir = find_mountpoint_for (path, path_dev);
+  if (mount_dir == NULL)
+    goto out;
+
+  mount_dir_len = strlen (mount_dir);
+  /* We special-case rootfs ('/') since it's the only case where
+   * mount_dir ends in '/'
+   */
+  if (mount_dir_len == 1)
+    mount_dir_len--;
+  if (mount_dir_len + strlen ("/lost+found") != strlen (path))
+    goto out;
+
+  if (g_lstat (path, &statbuf) != 0)
+    goto out;
+
+  if (!(S_ISDIR (statbuf.st_mode) &&
+        statbuf.st_uid == 0 &&
+        statbuf.st_gid == 0))
+    goto out;
+
+  ret = TRUE;
+
+ out:
+  g_free (mount_dir);
+  return ret;
+}
+#endif
 
 static gboolean
 g_local_file_trash (GFile         *file,
index 6dfd75f..831a20b 100644 (file)
@@ -1782,6 +1782,11 @@ _g_local_file_info_get (const char             *basename,
   if (stat_ok)
     set_info_from_stat (info, &statbuf, attribute_matcher);
 
+#ifdef G_OS_UNIX
+  if (stat_ok && _g_local_file_is_lost_found_dir (path, statbuf.st_dev))
+    g_file_info_set_is_hidden (info, TRUE);
+#endif
+
 #ifndef G_OS_WIN32
   if (basename != NULL &&
       (basename[0] == '.' ||
index bb711a2..6d35be5 100644 (file)
@@ -58,6 +58,10 @@ typedef struct
 
 gboolean   _g_local_file_has_trash_dir        (const char             *dirname,
                                                dev_t                   dir_dev);
+#ifdef G_OS_UNIX
+gboolean   _g_local_file_is_lost_found_dir    (const char             *path,
+                                               dev_t                   path_dev);
+#endif
 void       _g_local_file_info_get_parent_info (const char             *dir,
                                                GFileAttributeMatcher  *attribute_matcher,
                                                GLocalParentFileInfo   *parent_info);