patches/glib-04-gio-trash-only-home.diff
author dcarbery
Thu, 03 Jul 2008 13:03:20 +0000
changeset 12755 378c127fb033
parent 12077 57a76f58c89c
child 15616 6ba9f6e77e09
permissions -rw-r--r--
2008-07-03 Damien Carbery <[email protected]> * base-specs/gtk2.spec: Mark patch 17 as upstream. * patches/gtk+-17-gail-uninstalled.diff: Update with upstream version. * base-specs/glib2.spec: Bump to 2.17.3. * patches/glib-04-gio-trash-only-home.diff: Rework one hunk.

--- /usr/tmp/clean/glib-2.16.2/gio/glocalfile.c	2008-03-31 21:45:06.000000000 +0100
+++ glib-2.16.2/gio/glocalfile.c	2008-04-10 08:13:21.838298000 +0100
@@ -1668,6 +1668,7 @@
   int fd;
   struct stat trash_stat, global_stat;
   char *dirname, *globaldir;
+  GFile *trash;
   
   if (g_lstat (local->filename, &file_stat) != 0)
     {
@@ -1704,123 +1704,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 */
 
@@ -1865,8 +1769,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;
 
@@ -1874,6 +1778,7 @@
       g_free (trashname);
       g_free (infofile);
       g_free (trashfile);
+      g_object_unref(trash);
       
       g_set_error (error, G_IO_ERROR,
 		   g_io_error_from_errno (errsv),
@@ -1883,6 +1788,7 @@
     }
 
   g_free (trashfile);
+  g_object_unref(trash);
 
   /* TODO: Do we need to update mtime/atime here after the move? */