[gnome-settings-daemon] housekeeping: Don't follow symlinks to subdirectories



commit dd2477bf74510237310d41974ba3e342e6c95da1
Author: Bastien Nocera <hadess hadess net>
Date:   Mon May 19 12:58:07 2014 +0200

    housekeeping: Don't follow symlinks to subdirectories
    
    Check whether a leaf node is a symlink before processing it, and if it
    is, check whether we should delete the link itself.
    
    This works around a possible bug in GIO where GFileEnumerators will get
    the filetype of the linked-to item, instead of detecting that it is a
    symlink.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730223

 plugins/housekeeping/gsd-disk-space.c |   53 ++++++++++++++++++++++++++++-----
 1 files changed, 45 insertions(+), 8 deletions(-)
---
diff --git a/plugins/housekeeping/gsd-disk-space.c b/plugins/housekeeping/gsd-disk-space.c
index 77b1d70..e4edb2f 100644
--- a/plugins/housekeeping/gsd-disk-space.c
+++ b/plugins/housekeeping/gsd-disk-space.c
@@ -415,6 +415,44 @@ delete_subdir (GObject      *source,
         delete_data_unref (data);
 }
 
+static void
+delete_subdir_check_symlink (GObject      *source,
+                             GAsyncResult *res,
+                             gpointer      user_data)
+{
+        GFile *file = G_FILE (source);
+        DeleteData *data = user_data;
+        GFileInfo *info;
+        GFileType type;
+
+        info = g_file_query_info_finish (file, res, NULL);
+        if (!info) {
+                delete_data_unref (data);
+                return;
+        }
+
+        type = g_file_info_get_file_type (info);
+        g_object_unref (info);
+
+        if (type == G_FILE_TYPE_DIRECTORY) {
+                g_file_enumerate_children_async (data->file,
+                                                 G_FILE_ATTRIBUTE_STANDARD_NAME ","
+                                                 G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                                 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                                 0,
+                                                 data->cancellable,
+                                                 delete_subdir,
+                                                 delete_data_ref (data));
+        } else if (type == G_FILE_TYPE_SYMBOLIC_LINK) {
+                if (should_purge_file (data->file, data->cancellable, data->old)) {
+                        if (!data->dry_run) {
+                                g_file_delete (data->file, data->cancellable, NULL);
+                        }
+                }
+        }
+        delete_data_unref (data);
+}
+
 void
 delete_recursively_by_age (DeleteData *data)
 {
@@ -424,14 +462,13 @@ delete_recursively_by_age (DeleteData *data)
                 return;
         }
 
-        g_file_enumerate_children_async (data->file,
-                                         G_FILE_ATTRIBUTE_STANDARD_NAME ","
-                                         G_FILE_ATTRIBUTE_STANDARD_TYPE,
-                                         G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                         0,
-                                         data->cancellable,
-                                         delete_subdir,
-                                         delete_data_ref (data));
+        g_file_query_info_async (data->file,
+                                 G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                 0,
+                                 data->cancellable,
+                                 delete_subdir_check_symlink,
+                                 delete_data_ref (data));
 }
 
 void


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