glib r6533 - trunk/gio



Author: alexl
Date: Mon Feb 18 15:35:16 2008
New Revision: 6533
URL: http://svn.gnome.org/viewvc/glib?rev=6533&view=rev

Log:
2008-02-18  Alexander Larsson  <alexl redhat com>

        * glocalfile.c:
        * glocalfileinfo.c:
        * glocalfileoutputstream.c:
	Use g_unlink/g_rename instead of unlink/rename;
	do not pass raw filenames to g_set_error. (#517239)
	Patch from Yevgen Muntyan.



Modified:
   trunk/gio/ChangeLog
   trunk/gio/glocalfile.c
   trunk/gio/glocalfileinfo.c
   trunk/gio/glocalfileoutputstream.c

Modified: trunk/gio/glocalfile.c
==============================================================================
--- trunk/gio/glocalfile.c	(original)
+++ trunk/gio/glocalfile.c	Mon Feb 18 15:35:16 2008
@@ -989,7 +989,7 @@
       return NULL;
     }
 
-  if (rename (local->filename, new_local->filename) == -1)
+  if (g_rename (local->filename, new_local->filename) == -1)
     {
       errsv = errno;
 
@@ -1882,7 +1882,7 @@
   if (flags & G_FILE_COPY_BACKUP && destination_exist)
     {
       backup_name = g_strconcat (local_destination->filename, "~", NULL);
-      if (rename (local_destination->filename, backup_name) == -1)
+      if (g_rename (local_destination->filename, backup_name) == -1)
 	{
       	  g_set_error (error,
 		       G_IO_ERROR,
@@ -1899,7 +1899,7 @@
     {
       /* Source is a dir, destination exists (and is not a dir, because that would have failed
 	 earlier), and we're overwriting. Manually remove the target so we can do the rename. */
-      res = unlink (local_destination->filename);
+      res = g_unlink (local_destination->filename);
       if (res == -1)
 	{
           int errsv = errno;
@@ -1912,7 +1912,7 @@
 	}
     }
   
-  if (rename (local_source->filename, local_destination->filename) == -1)
+  if (g_rename (local_source->filename, local_destination->filename) == -1)
     {
       int errsv = errno;
 

Modified: trunk/gio/glocalfileinfo.c
==============================================================================
--- trunk/gio/glocalfileinfo.c	(original)
+++ trunk/gio/glocalfileinfo.c	Mon Feb 18 15:35:16 2008
@@ -1389,12 +1389,13 @@
   if (res == -1)
     {
       int errsv = errno;
-
+      char *display_name = g_filename_display_name (path);
       g_object_unref (info);
       g_set_error (error, G_IO_ERROR,
 		   g_io_error_from_errno (errsv),
 		   _("Error stating file '%s': %s"),
-		   path, g_strerror (errsv));
+		   display_name, g_strerror (errsv));
+      g_free (display_name);
       return NULL;
     }
   

Modified: trunk/gio/glocalfileoutputstream.c
==============================================================================
--- trunk/gio/glocalfileoutputstream.c	(original)
+++ trunk/gio/glocalfileoutputstream.c	Mon Feb 18 15:35:16 2008
@@ -203,7 +203,7 @@
 	  
 #ifdef HAVE_LINK
 	  /* create original -> backup link, the original is then renamed over */
-	  if (unlink (file->priv->backup_filename) != 0 &&
+	  if (g_unlink (file->priv->backup_filename) != 0 &&
 	      errno != ENOENT)
 	    {
               int errsv = errno;
@@ -218,7 +218,7 @@
 	  if (link (file->priv->original_filename, file->priv->backup_filename) != 0)
 	    {
 	      /*  link failed or is not supported, try rename  */
-	      if (rename (file->priv->original_filename, file->priv->backup_filename) != 0)
+	      if (g_rename (file->priv->original_filename, file->priv->backup_filename) != 0)
 		{
                   int errsv = errno;
 
@@ -231,7 +231,7 @@
 	    }
 #else
 	    /* If link not supported, just rename... */
-	  if (rename (file->priv->original_filename, file->priv->backup_filename) != 0)
+	  if (g_rename (file->priv->original_filename, file->priv->backup_filename) != 0)
 	    {
               int errsv = errno;
 
@@ -249,7 +249,7 @@
 	goto err_out;
 
       /* tmp -> original */
-      if (rename (file->priv->tmp_filename, file->priv->original_filename) != 0)
+      if (g_rename (file->priv->tmp_filename, file->priv->original_filename) != 0)
 	{
           int errsv = errno;
 
@@ -471,10 +471,14 @@
 		     G_IO_ERROR_INVALID_FILENAME,
 		     _("Invalid filename"));
       else
-	g_set_error (error, G_IO_ERROR,
-		     g_io_error_from_errno (errsv),
-		     _("Error opening file '%s': %s"),
-		     filename, g_strerror (errsv));
+	{
+	  char *display_name = g_filename_display_name (filename);
+	  g_set_error (error, G_IO_ERROR,
+		       g_io_error_from_errno (errsv),
+		       _("Error opening file '%s': %s"),
+		       display_name, g_strerror (errsv));
+	  g_free (display_name);
+	}
       return NULL;
     }
   
@@ -512,10 +516,14 @@
 		     G_IO_ERROR_INVALID_FILENAME,
 		     _("Invalid filename"));
       else
-	g_set_error (error, G_IO_ERROR,
-		     g_io_error_from_errno (errsv),
-		     _("Error opening file '%s': %s"),
-		     filename, g_strerror (errsv));
+	{
+	  char *display_name = g_filename_display_name (filename);
+	  g_set_error (error, G_IO_ERROR,
+		       g_io_error_from_errno (errsv),
+		       _("Error opening file '%s': %s"),
+		       display_name, g_strerror (errsv));
+	  g_free (display_name);
+	}
       return NULL;
     }
   
@@ -640,22 +648,24 @@
   if (fd == -1)
     {
       int errsv = errno;
-
+      char *display_name = g_filename_display_name (filename);
       g_set_error (error, G_IO_ERROR,
 		   g_io_error_from_errno (errsv),
 		   _("Error opening file '%s': %s"),
-		   filename, g_strerror (errsv));
+		   display_name, g_strerror (errsv));
+      g_free (display_name);
       return -1;
     }
   
   if (fstat (fd, &original_stat) != 0) 
     {
       int errsv = errno;
-
+      char *display_name = g_filename_display_name (filename);
       g_set_error (error, G_IO_ERROR,
 		   g_io_error_from_errno (errsv),
 		   _("Error stating file '%s': %s"),
-		   filename, g_strerror (errsv));
+		   display_name, g_strerror (errsv));
+      g_free (display_name);
       goto err_out;
     }
   
@@ -738,7 +748,7 @@
 	      original_stat.st_mode != tmp_statbuf.st_mode)
 	    {
 	      close (tmpfd);
-	      unlink (tmp_filename);
+	      g_unlink (tmp_filename);
 	      g_free (tmp_filename);
 	      goto fallback_strategy;
 	    }
@@ -759,7 +769,7 @@
       
       backup_filename = create_backup_filename (filename);
 
-      if (unlink (backup_filename) == -1 && errno != ENOENT)
+      if (g_unlink (backup_filename) == -1 && errno != ENOENT)
 	{
 	  g_set_error (error,
 		       G_IO_ERROR,
@@ -794,7 +804,7 @@
 		       G_IO_ERROR,
 		       G_IO_ERROR_CANT_CREATE_BACKUP,
 		       _("Backup file creation failed"));
-	  unlink (backup_filename);
+	  g_unlink (backup_filename);
 	  g_free (backup_filename);
 	  goto err_out;
 	}
@@ -810,7 +820,7 @@
 			   G_IO_ERROR,
 			   G_IO_ERROR_CANT_CREATE_BACKUP,
 			   _("Backup file creation failed"));
-	      unlink (backup_filename);
+	      g_unlink (backup_filename);
 	      close (bfd);
 	      g_free (backup_filename);
 	      goto err_out;
@@ -824,7 +834,7 @@
 		       G_IO_ERROR,
 		       G_IO_ERROR_CANT_CREATE_BACKUP,
 		       _("Backup file creation failed"));
-	  unlink (backup_filename);
+	  g_unlink (backup_filename);
 	  close (bfd);
 	  g_free (backup_filename);
 	  
@@ -914,10 +924,14 @@
 		     G_IO_ERROR_INVALID_FILENAME,
 		     _("Invalid filename"));
       else
-	g_set_error (error, G_IO_ERROR,
-		     g_io_error_from_errno (errsv),
-		     _("Error opening file '%s': %s"),
-		     filename, g_strerror (errsv));
+	{
+	  char *display_name = g_filename_display_name (filename);
+	  g_set_error (error, G_IO_ERROR,
+		       g_io_error_from_errno (errsv),
+		       _("Error opening file '%s': %s"),
+		       display_name, g_strerror (errsv));
+	  g_free (display_name);
+	}
       return NULL;
     }
   



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