From 218573323514fc0d69929fa0d92a523c254a474e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 6 Feb 2008 10:06:54 +0000 Subject: [PATCH] Don't succeed with trash if newly created trash dir has the wrong owner. 2008-02-06 Alexander Larsson * glocalfile.c (g_local_file_trash): Don't succeed with trash if newly created trash dir has the wrong owner. (#514696) svn path=/trunk/; revision=6459 --- gio/ChangeLog | 6 ++++++ gio/glocalfile.c | 28 ++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gio/ChangeLog b/gio/ChangeLog index 34bd524..8838eda 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,9 @@ +2008-02-06 Alexander Larsson + + * glocalfile.c (g_local_file_trash): + Don't succeed with trash if newly created + trash dir has the wrong owner. (#514696) + 2008-02-05 Alexander Larsson * glocalfile.c (g_local_file_move): diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 55ed4da..4c49a1c 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -1546,25 +1546,45 @@ g_local_file_trash (GFile *file, if (trashdir == NULL) { + gboolean tried_create; + /* No global trash dir, or it failed the tests, fall back to $topdir/.Trash-$uid */ dirname = g_strdup_printf (".Trash-%s", uid_str); trashdir = g_build_filename (topdir, dirname, NULL); g_free (dirname); - + + tried_create = FALSE; + + retry: if (g_lstat (trashdir, &trash_stat) == 0) { if (!S_ISDIR (trash_stat.st_mode) || trash_stat.st_uid != uid) { + /* Remove the failed directory */ + if (tried_create) + g_remove (trashdir); + /* Not a directory or not owned by user, ignore */ g_free (trashdir); trashdir = NULL; } } - else if (g_mkdir (trashdir, 0700) == -1) + else { - g_free (trashdir); - trashdir = NULL; + if (!tried_create && + g_mkdir (trashdir, 0700) != -1) + { + /* Ensure that the created dir has the right uid etc. + This might fail on e.g. a FAT dir */ + tried_create = TRUE; + goto retry; + } + else + { + g_free (trashdir); + trashdir = NULL; + } } } #endif -- 2.7.4