--- glib-2.20.1/gio/glocalfile.c.ori 2009-04-15 03:46:56.161574399 +0100
+++ glib-2.20.1/gio/glocalfile.c 2009-04-15 03:48:57.698109713 +0100
@@ -1732,123 +1733,26 @@
is_homedir_trash = FALSE;
trashdir = NULL;
- if (file_stat.st_dev == home_stat.st_dev)
+ /* Always move to .Trash in the user's home directory
+ */
+ is_homedir_trash = TRUE;
+ errno = 0;
+ trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
+ if (g_mkdir_with_parents (trashdir, 0700) < 0)
{
- is_homedir_trash = TRUE;
- errno = 0;
- trashdir = g_build_filename (g_get_user_data_dir (), "Trash", NULL);
- if (g_mkdir_with_parents (trashdir, 0700) < 0)
- {
- char *display_name;
- int errsv = errno;
-
- display_name = g_filename_display_name (trashdir);
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errsv),
- _("Unable to create trash dir %s: %s"),
- display_name, g_strerror (errsv));
- g_free (display_name);
- g_free (trashdir);
- return FALSE;
- }
- topdir = g_strdup (g_get_user_data_dir ());
- }
- else
- {
- uid_t uid;
- char uid_str[32];
-
- uid = geteuid ();
- g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
-
- topdir = find_topdir_for (local->filename);
- if (topdir == NULL)
- {
- g_set_error_literal (error, G_IO_ERROR,
- G_IO_ERROR_NOT_SUPPORTED,
- _("Unable to find toplevel directory for trash"));
- return FALSE;
- }
-
- /* Try looking for global trash dir $topdir/.Trash/$uid */
- globaldir = g_build_filename (topdir, ".Trash", NULL);
- if (g_lstat (globaldir, &global_stat) == 0 &&
- S_ISDIR (global_stat.st_mode) &&
- (global_stat.st_mode & S_ISVTX) != 0)
- {
- trashdir = g_build_filename (globaldir, uid_str, NULL);
-
- if (g_lstat (trashdir, &trash_stat) == 0)
- {
- if (!S_ISDIR (trash_stat.st_mode) ||
- trash_stat.st_uid != uid)
- {
- /* Not a directory or not owned by user, ignore */
- g_free (trashdir);
- trashdir = NULL;
- }
- }
- else if (g_mkdir (trashdir, 0700) == -1)
- {
- g_free (trashdir);
- trashdir = NULL;
- }
- }
- g_free (globaldir);
-
- 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 (!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;
- }
- }
- }
+ char *display_name;
+ int errsv = errno;
- if (trashdir == NULL)
- {
- g_free (topdir);
- g_set_error_literal (error, G_IO_ERROR,
- G_IO_ERROR_NOT_SUPPORTED,
- _("Unable to find or create trash directory"));
- return FALSE;
- }
+ display_name = g_filename_display_name (trashdir);
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ _("Unable to create trash dir %s: %s"),
+ display_name, g_strerror (errsv));
+ g_free (display_name);
+ g_free (trashdir);
+ return FALSE;
}
+ topdir = g_strdup (g_get_user_data_dir ());
/* Trashdir points to the trash dir with the "info" and "files" subdirectories */
@@ -1912,8 +1816,8 @@
trashfile = g_build_filename (filesdir, trashname, NULL);
g_free (filesdir);
-
- if (g_rename (local->filename, trashfile) == -1)
+ trash = g_file_new_for_path(trashfile);
+ if (!g_file_move (file, trash, 0, cancellable, NULL, NULL, NULL))
{
int errsv = errno;
@@ -1921,6 +1825,7 @@
g_free (trashname);
g_free (infofile);
g_free (trashfile);
+ g_object_unref(trash);
if (errsv == EXDEV)
/* The trash dir was actually on another fs anyway!?
diff -ruN glib-2.23.5.orig/gio/glocalfile.c glib-2.23.5/gio/glocalfile.c
--- glib-2.23.5.orig/gio/glocalfile.c 2010-03-12 01:24:16.709204235 +0000
+++ glib-2.23.5/gio/glocalfile.c 2010-03-12 01:25:06.966511383 +0000
@@ -1806,6 +1806,7 @@
char *dirname, *globaldir;
GVfsClass *class;
GVfs *vfs;
+ GFile *trash;
if (g_lstat (local->filename, &file_stat) != 0)
{
@@ -1939,6 +1940,7 @@
class->local_file_moved (vfs, local->filename, trashfile);
g_free (trashfile);
+ g_object_unref(trash);
/* TODO: Do we need to update mtime/atime here after the move? */