From 3b1b6a9722f40495762fbb115a43b39d495c3170 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 18 Feb 2008 15:35:16 +0000 Subject: [PATCH] Use g_unlink/g_rename instead of unlink/rename; do not pass raw filenames 2008-02-18 Alexander Larsson * 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. svn path=/trunk/; revision=6533 --- gio/ChangeLog | 9 +++++++ gio/glocalfile.c | 8 +++--- gio/glocalfileinfo.c | 5 ++-- gio/glocalfileoutputstream.c | 64 +++++++++++++++++++++++++++----------------- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/gio/ChangeLog b/gio/ChangeLog index e8698ab..6f92ab5 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,6 +1,15 @@ 2008-02-18 Alexander Larsson * 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. + +2008-02-18 Alexander Larsson + + * glocalfile.c: * glocalfileoutputstream.c: Open files with O_BINARY on windows. (#517140) diff --git a/gio/glocalfile.c b/gio/glocalfile.c index c9f6e59..b6816d1 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -989,7 +989,7 @@ g_local_file_set_display_name (GFile *file, 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 @@ g_local_file_move (GFile *source, 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 @@ g_local_file_move (GFile *source, { /* 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 @@ g_local_file_move (GFile *source, } } - if (rename (local_source->filename, local_destination->filename) == -1) + if (g_rename (local_source->filename, local_destination->filename) == -1) { int errsv = errno; diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index d5b028e..fa453ef 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -1389,12 +1389,13 @@ _g_local_file_info_get (const char *basename, 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; } diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c index ea304e9..cc2b120 100644 --- a/gio/glocalfileoutputstream.c +++ b/gio/glocalfileoutputstream.c @@ -203,7 +203,7 @@ g_local_file_output_stream_close (GOutputStream *stream, #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 @@ g_local_file_output_stream_close (GOutputStream *stream, 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 @@ g_local_file_output_stream_close (GOutputStream *stream, } #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 @@ g_local_file_output_stream_close (GOutputStream *stream, 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_local_file_output_stream_create (const char *filename, 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_local_file_output_stream_append (const char *filename, 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 @@ handle_overwrite_open (const char *filename, 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 @@ handle_overwrite_open (const char *filename, 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 @@ handle_overwrite_open (const char *filename, 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 @@ handle_overwrite_open (const char *filename, 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 @@ handle_overwrite_open (const char *filename, 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 @@ handle_overwrite_open (const char *filename, 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_local_file_output_stream_replace (const char *filename, 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; } -- 2.7.4