glocalfile: Fix the global trash dir detection

The `g_file_trash` function fails with the `Unable to find or create trash
directory` error when the global `.Trash` directory exists. This is because
the commit 7f2af262 introduced the `gboolean success` variable to signalize
the detection of the trash folder, but didn't set it in all code branches.
Since for a time this variable was not initialized the bug wasn't visible
when the trash folder existed. The bug became effective after the `success`
variable was initialized with `FALSE` by the commit c983ded0. Let's explicitly
set the `success` variable in all branches to fix the global trash dir
detection.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2439
This commit is contained in:
markus 2021-07-12 00:16:20 +02:00 committed by Philip Withnall
parent cd93c350a2
commit 648994dba4

View File

@ -2070,6 +2070,7 @@ g_local_file_trash (GFile *file,
(global_stat.st_mode & S_ISVTX) != 0) (global_stat.st_mode & S_ISVTX) != 0)
{ {
trashdir = g_build_filename (globaldir, uid_str, NULL); trashdir = g_build_filename (globaldir, uid_str, NULL);
success = TRUE;
if (g_lstat (trashdir, &trash_stat) == 0) if (g_lstat (trashdir, &trash_stat) == 0)
{ {
@ -2079,12 +2080,14 @@ g_local_file_trash (GFile *file,
/* Not a directory or not owned by user, ignore */ /* Not a directory or not owned by user, ignore */
g_free (trashdir); g_free (trashdir);
trashdir = NULL; trashdir = NULL;
success = FALSE;
} }
} }
else if (g_mkdir (trashdir, 0700) == -1) else if (g_mkdir (trashdir, 0700) == -1)
{ {
g_free (trashdir); g_free (trashdir);
trashdir = NULL; trashdir = NULL;
success = FALSE;
} }
} }
g_free (globaldir); g_free (globaldir);