Merge lp:~seb128/unity-settings-daemon/housekeeping_dont_follow_symlink into lp:unity-settings-daemon

Proposed by Sebastien Bacher on 2015-10-07
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2015-10-09
Approved revision: 4103
Merged at revision: 4106
Proposed branch: lp:~seb128/unity-settings-daemon/housekeeping_dont_follow_symlink
Merge into: lp:unity-settings-daemon
Diff against target: 147 lines (+68/-24)
2 files modified
plugins/housekeeping/gsd-disk-space.c (+48/-24)
plugins/housekeeping/gsd-disk-space.h (+20/-0)
To merge this branch: bzr merge lp:~seb128/unity-settings-daemon/housekeeping_dont_follow_symlink
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) 2015-10-07 Approve on 2015-10-09
Review via email: mp+273731@code.launchpad.net

Commit Message

housekeeping: Don't follow symlinks to subdirectories, that can lead to data being deleted that shouldn't

Description of the Change

housekeeping: Don't follow symlinks to subdirectories, that can lead to data being deleted that shouldn't

To post a comment you must log in.
Marco Trevisan (Treviño) (3v1n0) wrote :

Oh, this is a good one!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/housekeeping/gsd-disk-space.c'
2--- plugins/housekeeping/gsd-disk-space.c 2013-08-20 13:53:35 +0000
3+++ plugins/housekeeping/gsd-disk-space.c 2015-10-07 17:09:46 +0000
4@@ -270,18 +270,7 @@
5 return should_purge;
6 }
7
8-typedef struct {
9- gint ref_count;
10- GFile *file;
11- GCancellable *cancellable;
12- GDateTime *old;
13- gboolean dry_run;
14- gboolean trash;
15- gchar *name;
16- gint depth;
17-} DeleteData;
18-
19-static DeleteData *
20+DeleteData *
21 delete_data_new (GFile *file,
22 GCancellable *cancellable,
23 GDateTime *old,
24@@ -311,7 +300,7 @@
25 return data;
26 }
27
28-static void
29+void
30 delete_data_unref (DeleteData *data)
31 {
32 data->ref_count -= 1;
33@@ -326,8 +315,6 @@
34 g_free (data);
35 }
36
37-static void delete_recursively_by_age (DeleteData *data);
38-
39 static void
40 delete_batch (GObject *source,
41 GAsyncResult *res,
42@@ -415,7 +402,6 @@
43 } else if (data->depth > 0 && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY)) {
44 if ((data->trash && data->depth > 1) ||
45 should_purge_file (data->file, data->cancellable, data->old)) {
46- g_debug ("Purging %s leaf node", data->name);
47 if (!data->dry_run) {
48 g_file_delete (data->file, data->cancellable, NULL);
49 }
50@@ -428,6 +414,45 @@
51 }
52
53 static void
54+delete_subdir_check_symlink (GObject *source,
55+ GAsyncResult *res,
56+ gpointer user_data)
57+{
58+ GFile *file = G_FILE (source);
59+ DeleteData *data = user_data;
60+ GFileInfo *info;
61+ GFileType type;
62+
63+ info = g_file_query_info_finish (file, res, NULL);
64+ if (!info) {
65+ delete_data_unref (data);
66+ return;
67+ }
68+
69+ type = g_file_info_get_file_type (info);
70+ g_object_unref (info);
71+
72+ if (type == G_FILE_TYPE_SYMBOLIC_LINK) {
73+ if (should_purge_file (data->file, data->cancellable, data->old)) {
74+ g_debug ("Purging %s leaf node", data->name);
75+ if (!data->dry_run) {
76+ g_file_delete (data->file, data->cancellable, NULL);
77+ }
78+ }
79+ } else {
80+ g_file_enumerate_children_async (data->file,
81+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
82+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
83+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
84+ 0,
85+ data->cancellable,
86+ delete_subdir,
87+ delete_data_ref (data));
88+ }
89+ delete_data_unref (data);
90+}
91+
92+void
93 delete_recursively_by_age (DeleteData *data)
94 {
95 if (data->trash && (data->depth == 1) &&
96@@ -436,14 +461,13 @@
97 return;
98 }
99
100- g_file_enumerate_children_async (data->file,
101- G_FILE_ATTRIBUTE_STANDARD_NAME ","
102- G_FILE_ATTRIBUTE_STANDARD_TYPE,
103- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
104- 0,
105- data->cancellable,
106- delete_subdir,
107- delete_data_ref (data));
108+ g_file_query_info_async (data->file,
109+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
110+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
111+ 0,
112+ data->cancellable,
113+ delete_subdir_check_symlink,
114+ delete_data_ref (data));
115 }
116
117 void
118
119=== modified file 'plugins/housekeeping/gsd-disk-space.h'
120--- plugins/housekeeping/gsd-disk-space.h 2012-12-03 09:38:45 +0000
121+++ plugins/housekeeping/gsd-disk-space.h 2015-10-07 17:09:46 +0000
122@@ -28,6 +28,26 @@
123
124 G_BEGIN_DECLS
125
126+typedef struct {
127+ gint ref_count;
128+ GFile *file;
129+ GCancellable *cancellable;
130+ GDateTime *old;
131+ gboolean dry_run;
132+ gboolean trash;
133+ gchar *name;
134+ gint depth;
135+} DeleteData;
136+
137+void delete_data_unref (DeleteData *data);
138+DeleteData *delete_data_new (GFile *file,
139+ GCancellable *cancellable,
140+ GDateTime *old,
141+ gboolean dry_run,
142+ gboolean trash,
143+ gint depth);
144+void delete_recursively_by_age (DeleteData *data);
145+
146 void gsd_ldsm_setup (gboolean check_now);
147 void gsd_ldsm_clean (void);
148

Subscribers

People subscribed via source and target branches