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