/
08-gio-trash-only-home.patch
180 lines (170 loc) · 4.93 KB
/
08-gio-trash-only-home.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
--- glib-2.55.2/gio/glocalfile.c.~1~ 2018-01-09 00:34:19.000000000 +0000
+++ glib-2.55.2/gio/glocalfile.c 2018-02-16 12:20:09.786992190 +0000
@@ -1987,6 +1987,7 @@
char *dirname, *globaldir;
GVfsClass *class;
GVfs *vfs;
+ GFile *trash;
int errsv;
if (g_lstat (local->filename, &file_stat) != 0)
@@ -2004,123 +2005,26 @@
is_homedir_trash = FALSE;
trashdir = NULL;
- if (file_stat.st_dev == home_stat.st_dev)
- {
- is_homedir_trash = TRUE;
- errno = 0;
- trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
- if (g_mkdir_with_parents (trashdir, 0700) < 0)
- {
- char *display_name;
- errsv = errno;
-
- display_name = g_filename_display_name (trashdir);
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errsv),
- _("Unable to create trash dir %s: %s"),
- display_name, g_strerror (errsv));
- g_free (display_name);
- g_free (trashdir);
- return FALSE;
- }
- topdir = g_strdup (g_get_user_data_dir ());
- }
- else
- {
- uid_t uid;
- char uid_str[32];
-
- uid = geteuid ();
- g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
-
- topdir = _g_local_file_find_topdir_for (local->filename);
- if (topdir == NULL)
- {
- g_set_io_error (error,
- _("Unable to find toplevel directory to trash %s"),
- file, G_IO_ERROR_NOT_SUPPORTED);
- return FALSE;
- }
-
- /* Try looking for global trash dir $topdir/.Trash/$uid */
- globaldir = g_build_filename (topdir, ".Trash", NULL);
- if (g_lstat (globaldir, &global_stat) == 0 &&
- S_ISDIR (global_stat.st_mode) &&
- (global_stat.st_mode & S_ISVTX) != 0)
- {
- trashdir = g_build_filename (globaldir, uid_str, NULL);
-
- if (g_lstat (trashdir, &trash_stat) == 0)
- {
- if (!S_ISDIR (trash_stat.st_mode) ||
- trash_stat.st_uid != uid)
- {
- /* Not a directory or not owned by user, ignore */
- g_free (trashdir);
- trashdir = NULL;
- }
- }
- else if (g_mkdir (trashdir, 0700) == -1)
- {
- g_free (trashdir);
- trashdir = NULL;
- }
- }
- g_free (globaldir);
-
- if (trashdir == NULL)
- {
- gboolean tried_create;
-
- /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
- dirname = g_strdup_printf (".Trash-%s", uid_str);
- trashdir = g_build_filename (topdir, dirname, NULL);
- g_free (dirname);
-
- tried_create = FALSE;
-
- retry:
- if (g_lstat (trashdir, &trash_stat) == 0)
- {
- if (!S_ISDIR (trash_stat.st_mode) ||
- trash_stat.st_uid != uid)
- {
- /* Remove the failed directory */
- if (tried_create)
- g_remove (trashdir);
-
- /* Not a directory or not owned by user, ignore */
- g_free (trashdir);
- trashdir = NULL;
- }
- }
- else
- {
- if (!tried_create &&
- g_mkdir (trashdir, 0700) != -1)
- {
- /* Ensure that the created dir has the right uid etc.
- This might fail on e.g. a FAT dir */
- tried_create = TRUE;
- goto retry;
- }
- else
- {
- g_free (trashdir);
- trashdir = NULL;
- }
- }
- }
-
- if (trashdir == NULL)
- {
- g_free (topdir);
- g_set_io_error (error,
- _("Unable to find or create trash directory for %s"),
- file, G_IO_ERROR_NOT_SUPPORTED);
- return FALSE;
- }
+ /* Always move to .Trash in the user's home directory
+ */
+ is_homedir_trash = TRUE;
+ errno = 0;
+ trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
+ if (g_mkdir_with_parents (trashdir, 0700) < 0)
+ {
+ char *display_name;
+ int errsv = errno;
+
+ display_name = g_filename_display_name (trashdir);
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ _("Unable to create trash dir %s: %s"),
+ display_name, g_strerror (errsv));
+ g_free (display_name);
+ g_free (trashdir);
+ return FALSE;
}
+ topdir = g_strdup (g_get_user_data_dir ());
/* Trashdir points to the trash dir with the "info" and "files" subdirectories */
@@ -2213,8 +2117,8 @@
trashfile = g_build_filename (filesdir, trashname, NULL);
g_free (filesdir);
-
- if (g_rename (local->filename, trashfile) == -1)
+ trash = g_file_new_for_path(trashfile);
+ if (!g_file_move (file, trash, 0, cancellable, NULL, NULL, NULL))
{
errsv = errno;
@@ -2223,6 +2127,7 @@
g_free (trashname);
g_free (infofile);
g_free (trashfile);
+ g_object_unref(trash);
if (errsv == EXDEV)
/* The trash dir was actually on another fs anyway!?
@@ -2245,6 +2150,7 @@
class->local_file_moved (vfs, local->filename, trashfile);
g_free (trashfile);
+ g_object_unref(trash);
/* TODO: Do we need to update mtime/atime here after the move? */