summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-05-19 12:58:07 +0200
committerBastien Nocera <hadess@hadess.net>2014-05-19 17:05:21 +0200
commit4c2cd713f3086dccfbb039e2592d63ecefb3cc5a (patch)
tree6bd97cf64fcd682cc2f83589afbc530f544b00b8
parentdb610ba08b606cbedec79b8ca0e7ee051b29b59a (diff)
downloadgnome-settings-daemon-4c2cd713f3086dccfbb039e2592d63ecefb3cc5a.tar.gz
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
-rw-r--r--plugins/housekeeping/gsd-disk-space.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/plugins/housekeeping/gsd-disk-space.c b/plugins/housekeeping/gsd-disk-space.c
index 3256070a..fc909786 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