1 --- glib-2.66.4/gio/glocalfile.c.orig 2020-12-17 12:47:11.417608000 +0000
2 +++ glib-2.66.4/gio/glocalfile.c 2020-12-20 11:49:17.686916141 +0000
4 char *dirname, *globaldir;
10 if (glib_should_use_portal ())
11 --- a/gio/glocalfile.c
12 +++ b/gio/glocalfile.c
13 @@ -2039,146 +2039,25 @@ g_local_file_trash (GFile *file,
17 - if (file_stat.st_dev == home_stat.st_dev)
18 + /* Always move to .Trash in the user's home directory */
19 + is_homedir_trash = TRUE;
21 + trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
22 + if (g_mkdir_with_parents (trashdir, 0700) < 0)
24 - is_homedir_trash = TRUE;
26 - trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
27 - if (g_mkdir_with_parents (trashdir, 0700) < 0)
32 - display_name = g_filename_display_name (trashdir);
33 - g_set_error (error, G_IO_ERROR,
34 - g_io_error_from_errno (errsv),
35 - _("Unable to create trash directory %s: %s"),
36 - display_name, g_strerror (errsv));
37 - g_free (display_name);
41 - topdir = g_strdup (g_get_user_data_dir ());
47 - gboolean success = FALSE;
50 - g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
52 - topdir = _g_local_file_find_topdir_for (local->filename);
55 - g_set_io_error (error,
56 - _("Unable to find toplevel directory to trash %s"),
61 - if (ignore_trash_path (topdir))
63 - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
64 - _("Trashing on system internal mounts is not supported"));
70 - /* Try looking for global trash dir $topdir/.Trash/$uid */
71 - globaldir = g_build_filename (topdir, ".Trash", NULL);
72 - if (g_lstat (globaldir, &global_stat) == 0 &&
73 - S_ISDIR (global_stat.st_mode) &&
74 - (global_stat.st_mode & S_ISVTX) != 0)
76 - trashdir = g_build_filename (globaldir, uid_str, NULL);
79 - if (g_lstat (trashdir, &trash_stat) == 0)
81 - if (!S_ISDIR (trash_stat.st_mode) ||
82 - trash_stat.st_uid != uid)
84 - /* Not a directory or not owned by user, ignore */
90 - else if (g_mkdir (trashdir, 0700) == -1)
99 - if (trashdir == NULL)
101 - gboolean tried_create;
103 - /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
104 - dirname = g_strdup_printf (".Trash-%s", uid_str);
105 - trashdir = g_build_filename (topdir, dirname, NULL);
109 - tried_create = FALSE;
112 - if (g_lstat (trashdir, &trash_stat) == 0)
114 - if (!S_ISDIR (trash_stat.st_mode) ||
115 - trash_stat.st_uid != uid)
117 - /* Remove the failed directory */
119 - g_remove (trashdir);
121 - /* Not a directory or not owned by user, ignore */
127 - if (!tried_create &&
128 - g_mkdir (trashdir, 0700) != -1)
130 - /* Ensure that the created dir has the right uid etc.
131 - This might fail on e.g. a FAT dir */
132 - tried_create = TRUE;
144 - gchar *trashdir_display_name = NULL, *file_display_name = NULL;
146 - trashdir_display_name = g_filename_display_name (trashdir);
147 - file_display_name = g_filename_display_name (local->filename);
148 - g_set_error (error, G_IO_ERROR,
149 - G_IO_ERROR_NOT_SUPPORTED,
150 - _("Unable to find or create trash directory %s to trash %s"),
151 - trashdir_display_name, file_display_name);
153 - g_free (trashdir_display_name);
154 - g_free (file_display_name);
158 + char *display_name;
163 + display_name = g_filename_display_name (trashdir);
164 + g_set_error (error, G_IO_ERROR,
165 + g_io_error_from_errno (errsv),
166 + _("Unable to create trash directory %s: %s"),
167 + display_name, g_strerror (errsv));
168 + g_free (display_name);
172 + topdir = g_strdup (g_get_user_data_dir ());
174 /* Trashdir points to the trash dir with the "info" and "files" subdirectories */
176 @@ -2213,8 +2117,8 @@
177 trashfile = g_build_filename (filesdir, trashname, NULL);
181 - if (g_rename (local->filename, trashfile) == -1)
182 + trash = g_file_new_for_path(trashfile);
183 + if (!g_file_move (file, trash, 0, cancellable, NULL, NULL, NULL))
187 @@ -2223,6 +2127,7 @@
191 + g_object_unref(trash);
194 /* The trash dir was actually on another fs anyway!?
195 @@ -2245,6 +2150,7 @@
196 class->local_file_moved (vfs, local->filename, trashfile);
199 + g_object_unref(trash);
201 /* TODO: Do we need to update mtime/atime here after the move? */