Update Archive-Tar Perl distribution to 3.02 for Perl 5.36 and 5.38
[oi-userland.git] / components / library / glib / patches / 08-gio-trash-only-home.patch
blob522405acbc597b93bb86f97ac9bbf2830c471178
1 --- glib-2.82.0/gio/glocalfile.c.orig
2 +++ glib-2.82.0/gio/glocalfile.c
3 @@ -2000,6 +2000,7 @@
4 char *dirname, *globaldir;
5 GVfsClass *class;
6 GVfs *vfs;
7 + GFile *trash;
8 int errsv;
9 size_t basename_len;
10 GError *my_error = NULL;
11 @@ -2057,146 +2058,25 @@
12 g_free (path);
15 - if (file_stat.st_dev == home_stat.st_dev)
16 + /* Always move to .Trash in the user's home directory */
17 + is_homedir_trash = TRUE;
18 + errno = 0;
19 + trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
20 + if (g_mkdir_with_parents (trashdir, 0700) < 0)
22 - is_homedir_trash = TRUE;
23 - errno = 0;
24 - trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
25 - if (g_mkdir_with_parents (trashdir, 0700) < 0)
26 - {
27 - char *display_name;
28 - errsv = errno;
30 - display_name = g_filename_display_name (trashdir);
31 - g_set_error (error, G_IO_ERROR,
32 - g_io_error_from_errno (errsv),
33 - _("Unable to create trash directory %s: %s"),
34 - display_name, g_strerror (errsv));
35 - g_free (display_name);
36 - g_free (trashdir);
37 - return FALSE;
38 - }
39 - topdir = g_strdup (g_get_user_data_dir ());
40 - }
41 - else
42 - {
43 - uid_t uid;
44 - char uid_str[32];
45 - gboolean success = FALSE;
47 - uid = geteuid ();
48 - g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
50 - topdir = _g_local_file_find_topdir_for (local->filename);
51 - if (topdir == NULL)
52 - {
53 - g_set_io_error (error,
54 - _("Unable to find toplevel directory to trash %s"),
55 - file, ENOTSUP);
56 - return FALSE;
57 - }
59 - if (ignore_trash_path (topdir))
60 - {
61 - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
62 - _("Trashing on system internal mounts is not supported"));
63 - g_free (topdir);
65 - return FALSE;
66 - }
68 - /* Try looking for global trash dir $topdir/.Trash/$uid */
69 - globaldir = g_build_filename (topdir, ".Trash", NULL);
70 - if (g_lstat (globaldir, &global_stat) == 0 &&
71 - S_ISDIR (global_stat.st_mode) &&
72 - (global_stat.st_mode & S_ISVTX) != 0)
73 - {
74 - trashdir = g_build_filename (globaldir, uid_str, NULL);
75 - success = TRUE;
77 - if (g_lstat (trashdir, &trash_stat) == 0)
78 - {
79 - if (!S_ISDIR (trash_stat.st_mode) ||
80 - trash_stat.st_uid != uid)
81 - {
82 - /* Not a directory or not owned by user, ignore */
83 - g_free (trashdir);
84 - trashdir = NULL;
85 - success = FALSE;
86 - }
87 - }
88 - else if (g_mkdir (trashdir, 0700) == -1)
89 - {
90 - g_free (trashdir);
91 - trashdir = NULL;
92 - success = FALSE;
93 - }
94 - }
95 - g_free (globaldir);
97 - if (trashdir == NULL)
98 - {
99 - gboolean tried_create;
101 - /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */
102 - dirname = g_strdup_printf (".Trash-%s", uid_str);
103 - trashdir = g_build_filename (topdir, dirname, NULL);
104 - success = TRUE;
105 - g_free (dirname);
107 - tried_create = FALSE;
109 - retry:
110 - if (g_lstat (trashdir, &trash_stat) == 0)
112 - if (!S_ISDIR (trash_stat.st_mode) ||
113 - trash_stat.st_uid != uid)
115 - /* Remove the failed directory */
116 - if (tried_create)
117 - g_remove (trashdir);
119 - /* Not a directory or not owned by user, ignore */
120 - success = FALSE;
123 - else
125 - if (!tried_create &&
126 - g_mkdir (trashdir, 0700) != -1)
128 - /* Ensure that the created dir has the right uid etc.
129 - This might fail on e.g. a FAT dir */
130 - tried_create = TRUE;
131 - goto retry;
133 - else
135 - success = FALSE;
140 - if (!success)
142 - gchar *trashdir_display_name = NULL, *file_display_name = NULL;
144 - trashdir_display_name = g_filename_display_name (trashdir);
145 - file_display_name = g_filename_display_name (local->filename);
146 - g_set_error (error, G_IO_ERROR,
147 - G_IO_ERROR_NOT_SUPPORTED,
148 - _("Unable to find or create trash directory %s to trash %s"),
149 - trashdir_display_name, file_display_name);
151 - g_free (trashdir_display_name);
152 - g_free (file_display_name);
154 - g_free (topdir);
155 - g_free (trashdir);
156 + char *display_name;
157 + errsv = errno;
159 - return FALSE;
161 + display_name = g_filename_display_name (trashdir);
162 + g_set_error (error, G_IO_ERROR,
163 + g_io_error_from_errno (errsv),
164 + _("Unable to create trash directory %s: %s"),
165 + display_name, g_strerror (errsv));
166 + g_free (display_name);
167 + g_free (trashdir);
168 + return FALSE;
170 + topdir = g_strdup (g_get_user_data_dir ());
172 /* Trashdir points to the trash dir with the "info" and "files" subdirectories */
174 @@ -2366,8 +2246,8 @@
175 trashfile = g_build_filename (filesdir, trashname, NULL);
177 g_free (filesdir);
179 - if (g_rename (local->filename, trashfile) == -1)
180 + trash = g_file_new_for_path(trashfile);
181 + if (!g_file_move (file, trash, 0, cancellable, NULL, NULL, NULL))
183 errsv = errno;
185 @@ -2376,6 +2256,7 @@
186 g_free (trashname);
187 g_free (infofile);
188 g_free (trashfile);
189 + g_object_unref(trash);
191 if (errsv == EXDEV)
192 /* The trash dir was actually on another fs anyway!?
193 @@ -2398,6 +2279,7 @@
194 class->local_file_moved (vfs, local->filename, trashfile);
196 g_free (trashfile);
197 + g_object_unref(trash);
199 /* TODO: Do we need to update mtime/atime here after the move? */