[glib: 1/2] glocalfile: Fix the global trash dir detection




commit 648994dba41f02e6269e4e14911d58312827a0ba
Author: markus <markus schwarzenberg freenet de>
Date:   Mon Jul 12 00:16:20 2021 +0200

    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

 gio/glocalfile.c | 3 +++
 1 file changed, 3 insertions(+)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 873aa911f..0d4a44fd9 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -2070,6 +2070,7 @@ g_local_file_trash (GFile         *file,
          (global_stat.st_mode & S_ISVTX) != 0)
        {
          trashdir = g_build_filename (globaldir, uid_str, NULL);
+         success = TRUE;
 
          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 */
                  g_free (trashdir);
                  trashdir = NULL;
+                 success = FALSE;
                }
            }
          else if (g_mkdir (trashdir, 0700) == -1)
            {
              g_free (trashdir);
              trashdir = NULL;
+             success = FALSE;
            }
        }
       g_free (globaldir);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]