+2008-02-06 Christian Persch <chpe@gnome.org>
+
+ * gio/gdesktopappinfo.c: (ensure_dir):
+ * gio/glocalfile.c: (g_local_file_query_filesystem_info),
+ (g_local_file_read), (g_local_file_delete), (g_local_file_trash),
+ (g_local_file_move):
+ * gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
+ (_g_local_file_info_get_from_fd), (set_unix_mode),
+ (set_unix_uid_gid), (set_symlink), (set_mtime_atime):
+ * gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
+ (g_local_file_input_stream_skip),
+ (g_local_file_input_stream_close),
+ (g_local_file_input_stream_seek):
+ * gio/glocalfileoutputstream.c: (g_local_file_output_stream_write),
+ (g_local_file_output_stream_close),
+ (g_local_file_output_stream_seek),
+ (g_local_file_output_stream_truncate), (copy_file_data),
+ (handle_overwrite_open):
+ * gio/gunixinputstream.c: (g_unix_input_stream_read),
+ (g_unix_input_stream_close), (read_async_cb), (close_async_cb):
+ * gio/gunixoutputstream.c: (g_unix_output_stream_write),
+ (g_unix_output_stream_close), (write_async_cb), (close_async_cb): Save
+ errno before calling other funcs that potentially alter it. Bug
+ #514766.
+
2008-02-05 18:42:42 Tim Janik <timj@imendio.com>
* configure.in: generate gobject/tests/Makefile.
GError **error)
{
char *path, *display_name;
- int err;
+ int errsv;
if (type == APP_DIR)
path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
if (g_mkdir_with_parents (path, 0700) == 0)
return path;
- err = errno;
+ errsv = errno;
display_name = g_filename_display_name (path);
if (type == APP_DIR)
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (err),
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Can't create user application configuration folder %s: %s"),
- display_name, g_strerror (err));
+ display_name, g_strerror (errsv));
else
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (err),
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Can't create user MIME configuration folder %s: %s"),
- display_name, g_strerror (err));
+ display_name, g_strerror (errsv));
g_free (display_name);
g_free (path);
if (statfs_result == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error getting filesystem info: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return NULL;
}
fd = g_open (local->filename, O_RDONLY, 0);
if (fd == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error opening file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return NULL;
}
if (g_remove (local->filename) == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error removing file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
if (g_lstat (local->filename, &file_stat) != 0)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error trashing file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
if (g_mkdir_with_parents (trashdir, 0700) < 0)
{
char *display_name;
- int err;
+ int errsv = errno;
- err = errno;
display_name = g_filename_display_name (trashdir);
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (err),
+ g_io_error_from_errno (errsv),
_("Unable to create trash dir %s: %s"),
- display_name, g_strerror (err));
+ display_name, g_strerror (errsv));
g_free (display_name);
g_free (trashdir);
return FALSE;
if (fd == -1)
{
+ int errsv = errno;
+
g_free (filesdir);
g_free (topdir);
g_free (trashname);
g_free (infofile);
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Unable to create trashing info file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
if (g_rename (local->filename, trashfile) == -1)
{
+ int errsv = errno;
+
g_free (topdir);
g_free (trashname);
g_free (infofile);
g_free (trashfile);
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Unable to trash file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
res = g_lstat (local_source->filename, &statbuf);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error moving file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
else
res = unlink (local_destination->filename);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error removing target file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
}
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errsv),
_("Error setting extended attribute '%s': %s"),
- escaped_attribute, g_strerror (errno));
+ escaped_attribute, g_strerror (errsv));
return FALSE;
}
res = g_lstat (path, &statbuf);
if (res == -1)
{
+ int errsv = errno;
+
g_object_unref (info);
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error stating file '%s': %s"),
- path, g_strerror (errno));
+ path, g_strerror (errsv));
return NULL;
}
if (fstat (fd, &stat_buf) == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error stating file descriptor: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return NULL;
}
if (g_chmod (filename, val) == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error setting permissions: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
return TRUE;
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error setting owner: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
return TRUE;
if (g_lstat (filename, &statbuf))
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error setting symlink: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
if (g_unlink (filename))
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error setting symlink: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
if (symlink (filename, val) != 0)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error setting symlink: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
res = utimes (filename, times);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error setting owner: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
return TRUE;
res = read (file->priv->fd, buffer, count);
if (res == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
start = lseek (file->priv->fd, 0, SEEK_CUR);
if (start == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return -1;
}
res = lseek (file->priv->fd, count, SEEK_CUR);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return -1;
}
{
res = close (file->priv->fd);
if (res == -1)
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Error closing file: %s"),
- g_strerror (errno));
+ {
+ int errsv = errno;
+
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ _("Error closing file: %s"),
+ g_strerror (errsv));
+ }
break;
}
if (pos == (off_t)-1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
res = write (file->priv->fd, buffer, count);
if (res == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error writing to file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
if (unlink (file->priv->backup_filename) != 0 &&
errno != ENOENT)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Error removing old backup link: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
goto err_out;
}
/* link failed or is not supported, try rename */
if (rename (file->priv->original_filename, file->priv->backup_filename) != 0)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Error creating backup copy: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
goto err_out;
}
}
/* If link not supported, just rename... */
if (rename (file->priv->original_filename, file->priv->backup_filename) != 0)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Error creating backup copy: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
goto err_out;
}
#endif
/* tmp -> original */
if (rename (file->priv->tmp_filename, file->priv->original_filename) != 0)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
_("Error renaming temporary file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
goto err_out;
}
}
res = close (file->priv->fd);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error closing file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
}
if (pos == (off_t)-1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
if (res == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
{
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
}
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error truncating file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
bytes_read = read (sfd, buffer, BUFSIZE);
if (bytes_read == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
ret = FALSE;
break;
}
bytes_written = write (dfd, write_buffer, bytes_to_write);
if (bytes_written == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error writing to file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
ret = FALSE;
break;
}
if (fd == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error opening file '%s': %s"),
- filename, g_strerror (errno));
+ filename, g_strerror (errsv));
return -1;
}
if (fstat (fd, &original_stat) != 0)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error stating file '%s': %s"),
- filename, g_strerror (errno));
+ filename, g_strerror (errsv));
goto err_out;
}
/* Seek back to the start of the file after the backup copy */
if (lseek (fd, 0, SEEK_SET) == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
goto err_out;
}
}
if (ftruncate (fd, 0) == -1)
#endif
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error truncating file: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
goto err_out;
}
if (poll_ret == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return -1;
}
}
res = read (unix_stream->priv->fd, buffer, count);
if (res == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
/* This might block during the close. Doesn't seem to be a way to avoid it though. */
res = close (unix_stream->priv->fd);
if (res == -1)
- g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Error closing unix: %s"),
- g_strerror (errno));
+ {
+ int errsv = errno;
+
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ _("Error closing unix: %s"),
+ g_strerror (errsv));
+ }
break;
}
count_read = read (data->stream->priv->fd, data->buffer, data->count);
if (count_read == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (&error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
}
{
res = close (unix_stream->priv->fd);
if (res == -1)
- g_set_error (&error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Error closing unix: %s"),
- g_strerror (errno));
+ {
+ int errsv = errno;
+
+ g_set_error (&error, G_IO_ERROR,
+ g_io_error_from_errno (errsv),
+ _("Error closing unix: %s"),
+ g_strerror (errsv));
+ }
break;
}
if (poll_ret == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error writing to unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
return -1;
}
}
res = write (unix_stream->priv->fd, buffer, count);
if (res == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error writing to unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
res = close (unix_stream->priv->fd);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error closing unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
}
count_written = write (data->stream->priv->fd, data->buffer, data->count);
if (count_written == -1)
{
- if (errno == EINTR)
+ int errsv = errno;
+
+ if (errsv == EINTR)
continue;
g_set_error (&error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
}
res = close (unix_stream->priv->fd);
if (res == -1)
{
+ int errsv = errno;
+
g_set_error (&error, G_IO_ERROR,
- g_io_error_from_errno (errno),
+ g_io_error_from_errno (errsv),
_("Error closing unix: %s"),
- g_strerror (errno));
+ g_strerror (errsv));
}
break;
}