openexr: make architecture independent
[oi-userland.git] / components / library / glib / patches / 08-gio-trash-only-home.patch
blob5e145dd876aaaded0b253055a9f4cdde4e1fa25c
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
3 @@ -1956,6 +1956,7 @@
4 char *dirname, *globaldir;
5 GVfsClass *class;
6 GVfs *vfs;
7 + GFile *trash;
8 int errsv;
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,
14 g_free (path);
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;
20 + errno = 0;
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;
25 - errno = 0;
26 - trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
27 - if (g_mkdir_with_parents (trashdir, 0700) < 0)
28 - {
29 - char *display_name;
30 - errsv = errno;
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);
38 - g_free (trashdir);
39 - return FALSE;
40 - }
41 - topdir = g_strdup (g_get_user_data_dir ());
42 - }
43 - else
44 - {
45 - uid_t uid;
46 - char uid_str[32];
47 - gboolean success = FALSE;
49 - uid = geteuid ();
50 - g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
52 - topdir = _g_local_file_find_topdir_for (local->filename);
53 - if (topdir == NULL)
54 - {
55 - g_set_io_error (error,
56 - _("Unable to find toplevel directory to trash %s"),
57 - file, ENOTSUP);
58 - return FALSE;
59 - }
61 - if (ignore_trash_path (topdir))
62 - {
63 - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
64 - _("Trashing on system internal mounts is not supported"));
65 - g_free (topdir);
67 - return FALSE;
68 - }
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)
75 - {
76 - trashdir = g_build_filename (globaldir, uid_str, NULL);
77 - success = TRUE;
79 - if (g_lstat (trashdir, &trash_stat) == 0)
80 - {
81 - if (!S_ISDIR (trash_stat.st_mode) ||
82 - trash_stat.st_uid != uid)
83 - {
84 - /* Not a directory or not owned by user, ignore */
85 - g_free (trashdir);
86 - trashdir = NULL;
87 - success = FALSE;
88 - }
89 - }
90 - else if (g_mkdir (trashdir, 0700) == -1)
91 - {
92 - g_free (trashdir);
93 - trashdir = NULL;
94 - success = FALSE;
95 - }
96 - }
97 - g_free (globaldir);
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);
106 - success = TRUE;
107 - g_free (dirname);
109 - tried_create = FALSE;
111 - retry:
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 */
118 - if (tried_create)
119 - g_remove (trashdir);
121 - /* Not a directory or not owned by user, ignore */
122 - success = FALSE;
125 - else
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;
133 - goto retry;
135 - else
137 - success = FALSE;
142 - if (!success)
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);
156 - g_free (topdir);
157 - g_free (trashdir);
158 + char *display_name;
159 + errsv = errno;
161 - return FALSE;
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);
169 + g_free (trashdir);
170 + return FALSE;
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);
179 g_free (filesdir);
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))
185 errsv = errno;
187 @@ -2223,6 +2127,7 @@
188 g_free (trashname);
189 g_free (infofile);
190 g_free (trashfile);
191 + g_object_unref(trash);
193 if (errsv == EXDEV)
194 /* The trash dir was actually on another fs anyway!?
195 @@ -2245,6 +2150,7 @@
196 class->local_file_moved (vfs, local->filename, trashfile);
198 g_free (trashfile);
199 + g_object_unref(trash);
201 /* TODO: Do we need to update mtime/atime here after the move? */