[glib] fileinfo: mark lost+found/ root directory as hidden



commit d77948eadf39ff4fdc001f679c7628e84e3af461
Author: David Zeuthen <zeuthen gmail com>
Date:   Thu Dec 6 16:21:58 2012 -0500

    fileinfo: mark lost+found/ root directory as hidden
    
    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     |   40 ++++++++++++++++++++++++++++++++++++++++
 gio/glocalfileinfo.c |    5 +++++
 gio/glocalfileinfo.h |    4 ++++
 3 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index ae60870..db4a48a 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -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,
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 6dfd75f..831a20b 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -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] == '.' ||
diff --git a/gio/glocalfileinfo.h b/gio/glocalfileinfo.h
index bb711a2..6d35be5 100644
--- a/gio/glocalfileinfo.h
+++ b/gio/glocalfileinfo.h
@@ -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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]