1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include <sys/types.h>
35 #include <glib/gstdio.h>
38 #include "gcancellable.h"
39 #include "glocalfileoutputstream.h"
40 #include "glocalfileinfo.h"
45 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
48 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
58 #define g_local_file_output_stream_get_type _g_local_file_output_stream_get_type
59 G_DEFINE_TYPE (GLocalFileOutputStream, g_local_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM);
61 /* Some of the file replacement code was based on the code from gedit,
62 * relicenced to LGPL with permissions from the authors.
65 #define BACKUP_EXTENSION "~"
67 struct _GLocalFileOutputStreamPrivate {
69 char *original_filename;
70 char *backup_filename;
72 guint sync_on_close : 1;
77 static gssize g_local_file_output_stream_write (GOutputStream *stream,
80 GCancellable *cancellable,
82 static gboolean g_local_file_output_stream_close (GOutputStream *stream,
83 GCancellable *cancellable,
85 static GFileInfo *g_local_file_output_stream_query_info (GFileOutputStream *stream,
86 const char *attributes,
87 GCancellable *cancellable,
89 static char * g_local_file_output_stream_get_etag (GFileOutputStream *stream);
90 static goffset g_local_file_output_stream_tell (GFileOutputStream *stream);
91 static gboolean g_local_file_output_stream_can_seek (GFileOutputStream *stream);
92 static gboolean g_local_file_output_stream_seek (GFileOutputStream *stream,
95 GCancellable *cancellable,
97 static gboolean g_local_file_output_stream_can_truncate (GFileOutputStream *stream);
98 static gboolean g_local_file_output_stream_truncate (GFileOutputStream *stream,
100 GCancellable *cancellable,
104 g_local_file_output_stream_finalize (GObject *object)
106 GLocalFileOutputStream *file;
108 file = G_LOCAL_FILE_OUTPUT_STREAM (object);
110 g_free (file->priv->tmp_filename);
111 g_free (file->priv->original_filename);
112 g_free (file->priv->backup_filename);
113 g_free (file->priv->etag);
115 G_OBJECT_CLASS (g_local_file_output_stream_parent_class)->finalize (object);
119 g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
121 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
122 GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
123 GFileOutputStreamClass *file_stream_class = G_FILE_OUTPUT_STREAM_CLASS (klass);
125 g_type_class_add_private (klass, sizeof (GLocalFileOutputStreamPrivate));
127 gobject_class->finalize = g_local_file_output_stream_finalize;
129 stream_class->write_fn = g_local_file_output_stream_write;
130 stream_class->close_fn = g_local_file_output_stream_close;
131 file_stream_class->query_info = g_local_file_output_stream_query_info;
132 file_stream_class->get_etag = g_local_file_output_stream_get_etag;
133 file_stream_class->tell = g_local_file_output_stream_tell;
134 file_stream_class->can_seek = g_local_file_output_stream_can_seek;
135 file_stream_class->seek = g_local_file_output_stream_seek;
136 file_stream_class->can_truncate = g_local_file_output_stream_can_truncate;
137 file_stream_class->truncate_fn = g_local_file_output_stream_truncate;
141 g_local_file_output_stream_init (GLocalFileOutputStream *stream)
143 stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream,
144 G_TYPE_LOCAL_FILE_OUTPUT_STREAM,
145 GLocalFileOutputStreamPrivate);
146 stream->priv->do_close = TRUE;
150 _g_local_file_output_stream_get_fd (GLocalFileOutputStream *out)
152 return out->priv->fd;
156 g_local_file_output_stream_write (GOutputStream *stream,
159 GCancellable *cancellable,
162 GLocalFileOutputStream *file;
165 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
169 if (g_cancellable_set_error_if_cancelled (cancellable, error))
171 res = write (file->priv->fd, buffer, count);
179 g_set_error (error, G_IO_ERROR,
180 g_io_error_from_errno (errsv),
181 _("Error writing to file: %s"),
192 _g_local_file_output_stream_set_do_close (GLocalFileOutputStream *out,
195 out->priv->do_close = do_close;
199 _g_local_file_output_stream_really_close (GLocalFileOutputStream *file,
200 GCancellable *cancellable,
203 GLocalFileStat final_stat;
207 if (file->priv->sync_on_close &&
208 fsync (file->priv->fd) != 0)
212 g_set_error (error, G_IO_ERROR,
213 g_io_error_from_errno (errsv),
214 _("Error writing to file: %s"),
222 /* Must close before renaming on Windows, so just do the close first
223 * in all cases for now.
225 if (_fstati64 (file->priv->fd, &final_stat) == 0)
226 file->priv->etag = _g_local_file_info_create_etag (&final_stat);
228 res = close (file->priv->fd);
233 g_set_error (error, G_IO_ERROR,
234 g_io_error_from_errno (errsv),
235 _("Error closing file: %s"),
242 if (file->priv->tmp_filename)
244 /* We need to move the temp file to its final place,
245 * and possibly create the backup file
248 if (file->priv->backup_filename)
250 if (g_cancellable_set_error_if_cancelled (cancellable, error))
254 /* create original -> backup link, the original is then renamed over */
255 if (g_unlink (file->priv->backup_filename) != 0 &&
260 g_set_error (error, G_IO_ERROR,
261 G_IO_ERROR_CANT_CREATE_BACKUP,
262 _("Error removing old backup link: %s"),
267 if (link (file->priv->original_filename, file->priv->backup_filename) != 0)
269 /* link failed or is not supported, try rename */
270 if (g_rename (file->priv->original_filename, file->priv->backup_filename) != 0)
274 g_set_error (error, G_IO_ERROR,
275 G_IO_ERROR_CANT_CREATE_BACKUP,
276 _("Error creating backup copy: %s"),
282 /* If link not supported, just rename... */
283 if (g_rename (file->priv->original_filename, file->priv->backup_filename) != 0)
287 g_set_error (error, G_IO_ERROR,
288 G_IO_ERROR_CANT_CREATE_BACKUP,
289 _("Error creating backup copy: %s"),
297 if (g_cancellable_set_error_if_cancelled (cancellable, error))
300 /* tmp -> original */
301 if (g_rename (file->priv->tmp_filename, file->priv->original_filename) != 0)
305 g_set_error (error, G_IO_ERROR,
306 g_io_error_from_errno (errsv),
307 _("Error renaming temporary file: %s"),
313 if (g_cancellable_set_error_if_cancelled (cancellable, error))
316 #ifndef G_OS_WIN32 /* Already did the fstat() and close() above on Win32 */
318 if (fstat (file->priv->fd, &final_stat) == 0)
319 file->priv->etag = _g_local_file_info_create_etag (&final_stat);
323 res = close (file->priv->fd);
328 g_set_error (error, G_IO_ERROR,
329 g_io_error_from_errno (errsv),
330 _("Error closing file: %s"),
347 /* A simple try to close the fd in case we fail before the actual close */
348 close (file->priv->fd);
355 g_local_file_output_stream_close (GOutputStream *stream,
356 GCancellable *cancellable,
359 GLocalFileOutputStream *file;
361 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
363 if (file->priv->do_close)
364 return _g_local_file_output_stream_really_close (file,
371 g_local_file_output_stream_get_etag (GFileOutputStream *stream)
373 GLocalFileOutputStream *file;
375 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
377 return g_strdup (file->priv->etag);
381 g_local_file_output_stream_tell (GFileOutputStream *stream)
383 GLocalFileOutputStream *file;
386 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
388 pos = lseek (file->priv->fd, 0, SEEK_CUR);
390 if (pos == (off_t)-1)
397 g_local_file_output_stream_can_seek (GFileOutputStream *stream)
399 GLocalFileOutputStream *file;
402 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
404 pos = lseek (file->priv->fd, 0, SEEK_CUR);
406 if (pos == (off_t)-1 && errno == ESPIPE)
413 seek_type_to_lseek (GSeekType type)
430 g_local_file_output_stream_seek (GFileOutputStream *stream,
433 GCancellable *cancellable,
436 GLocalFileOutputStream *file;
439 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
441 pos = lseek (file->priv->fd, offset, seek_type_to_lseek (type));
443 if (pos == (off_t)-1)
447 g_set_error (error, G_IO_ERROR,
448 g_io_error_from_errno (errsv),
449 _("Error seeking in file: %s"),
458 g_local_file_output_stream_can_truncate (GFileOutputStream *stream)
460 /* We can't truncate pipes and stuff where we can't seek */
461 return g_local_file_output_stream_can_seek (stream);
465 g_local_file_output_stream_truncate (GFileOutputStream *stream,
467 GCancellable *cancellable,
470 GLocalFileOutputStream *file;
473 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
477 res = g_win32_ftruncate (file->priv->fd, size);
479 res = ftruncate (file->priv->fd, size);
488 if (g_cancellable_set_error_if_cancelled (cancellable, error))
493 g_set_error (error, G_IO_ERROR,
494 g_io_error_from_errno (errsv),
495 _("Error truncating file: %s"),
505 g_local_file_output_stream_query_info (GFileOutputStream *stream,
506 const char *attributes,
507 GCancellable *cancellable,
510 GLocalFileOutputStream *file;
512 file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
514 if (g_cancellable_set_error_if_cancelled (cancellable, error))
517 return _g_local_file_info_get_from_fd (file->priv->fd,
523 _g_local_file_output_stream_open (const char *filename,
525 GCancellable *cancellable,
528 GLocalFileOutputStream *stream;
532 if (g_cancellable_set_error_if_cancelled (cancellable, error))
535 open_flags = O_BINARY;
537 open_flags |= O_RDWR;
539 open_flags |= O_WRONLY;
541 fd = g_open (filename, open_flags, 0666);
547 /* This must be an invalid filename, on e.g. FAT */
548 g_set_error_literal (error, G_IO_ERROR,
549 G_IO_ERROR_INVALID_FILENAME,
550 _("Invalid filename"));
553 char *display_name = g_filename_display_name (filename);
554 g_set_error (error, G_IO_ERROR,
555 g_io_error_from_errno (errsv),
556 _("Error opening file '%s': %s"),
557 display_name, g_strerror (errsv));
558 g_free (display_name);
563 stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
564 stream->priv->fd = fd;
565 return G_FILE_OUTPUT_STREAM (stream);
569 _g_local_file_output_stream_create (const char *filename,
571 GFileCreateFlags flags,
572 GCancellable *cancellable,
575 GLocalFileOutputStream *stream;
580 if (g_cancellable_set_error_if_cancelled (cancellable, error))
583 if (flags & G_FILE_CREATE_PRIVATE)
588 open_flags = O_CREAT | O_EXCL | O_BINARY;
590 open_flags |= O_RDWR;
592 open_flags |= O_WRONLY;
594 fd = g_open (filename, open_flags, mode);
600 /* This must be an invalid filename, on e.g. FAT */
601 g_set_error_literal (error, G_IO_ERROR,
602 G_IO_ERROR_INVALID_FILENAME,
603 _("Invalid filename"));
606 char *display_name = g_filename_display_name (filename);
607 g_set_error (error, G_IO_ERROR,
608 g_io_error_from_errno (errsv),
609 _("Error opening file '%s': %s"),
610 display_name, g_strerror (errsv));
611 g_free (display_name);
616 stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
617 stream->priv->fd = fd;
618 return G_FILE_OUTPUT_STREAM (stream);
622 _g_local_file_output_stream_append (const char *filename,
623 GFileCreateFlags flags,
624 GCancellable *cancellable,
627 GLocalFileOutputStream *stream;
631 if (g_cancellable_set_error_if_cancelled (cancellable, error))
634 if (flags & G_FILE_CREATE_PRIVATE)
639 fd = g_open (filename, O_CREAT | O_APPEND | O_WRONLY | O_BINARY, mode);
645 /* This must be an invalid filename, on e.g. FAT */
646 g_set_error_literal (error, G_IO_ERROR,
647 G_IO_ERROR_INVALID_FILENAME,
648 _("Invalid filename"));
651 char *display_name = g_filename_display_name (filename);
652 g_set_error (error, G_IO_ERROR,
653 g_io_error_from_errno (errsv),
654 _("Error opening file '%s': %s"),
655 display_name, g_strerror (errsv));
656 g_free (display_name);
661 stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
662 stream->priv->fd = fd;
664 return G_FILE_OUTPUT_STREAM (stream);
668 create_backup_filename (const char *filename)
670 return g_strconcat (filename, BACKUP_EXTENSION, NULL);
673 #define BUFSIZE 8192 /* size of normal write buffer */
676 copy_file_data (gint sfd,
682 const gchar *write_buffer;
684 gssize bytes_to_write;
685 gssize bytes_written;
687 buffer = g_malloc (BUFSIZE);
691 bytes_read = read (sfd, buffer, BUFSIZE);
692 if (bytes_read == -1)
699 g_set_error (error, G_IO_ERROR,
700 g_io_error_from_errno (errsv),
701 _("Error reading from file: %s"),
707 bytes_to_write = bytes_read;
708 write_buffer = buffer;
712 bytes_written = write (dfd, write_buffer, bytes_to_write);
713 if (bytes_written == -1)
720 g_set_error (error, G_IO_ERROR,
721 g_io_error_from_errno (errsv),
722 _("Error writing to file: %s"),
728 bytes_to_write -= bytes_written;
729 write_buffer += bytes_written;
731 while (bytes_to_write > 0);
733 } while ((bytes_read != 0) && (ret == TRUE));
741 handle_overwrite_open (const char *filename,
744 gboolean create_backup,
745 char **temp_filename,
746 GFileCreateFlags flags,
747 GCancellable *cancellable,
751 GLocalFileStat original_stat;
758 if (flags & G_FILE_CREATE_PRIVATE)
763 /* We only need read access to the original file if we are creating a backup.
764 * We also add O_CREATE to avoid a race if the file was just removed */
765 if (create_backup || readable)
766 open_flags = O_RDWR | O_CREAT | O_BINARY;
768 open_flags = O_WRONLY | O_CREAT | O_BINARY;
770 /* Some systems have O_NOFOLLOW, which lets us avoid some races
771 * when finding out if the file we opened was a symlink */
774 fd = g_open (filename, open_flags | O_NOFOLLOW, mode);
775 if (fd == -1 && errno == ELOOP)
777 /* Could be a symlink, or it could be a regular ELOOP error,
778 * but then the next open will fail too. */
780 fd = g_open (filename, open_flags, mode);
783 fd = g_open (filename, open_flags, mode);
784 /* This is racy, but we do it as soon as possible to minimize the race */
785 is_symlink = g_file_test (filename, G_FILE_TEST_IS_SYMLINK);
791 char *display_name = g_filename_display_name (filename);
792 g_set_error (error, G_IO_ERROR,
793 g_io_error_from_errno (errsv),
794 _("Error opening file '%s': %s"),
795 display_name, g_strerror (errsv));
796 g_free (display_name);
801 res = _fstati64 (fd, &original_stat);
803 res = fstat (fd, &original_stat);
809 char *display_name = g_filename_display_name (filename);
810 g_set_error (error, G_IO_ERROR,
811 g_io_error_from_errno (errsv),
812 _("Error stating file '%s': %s"),
813 display_name, g_strerror (errsv));
814 g_free (display_name);
818 /* not a regular file */
819 if (!S_ISREG (original_stat.st_mode))
821 if (S_ISDIR (original_stat.st_mode))
822 g_set_error_literal (error,
824 G_IO_ERROR_IS_DIRECTORY,
825 _("Target file is a directory"));
827 g_set_error_literal (error,
829 G_IO_ERROR_NOT_REGULAR_FILE,
830 _("Target file is not a regular file"));
836 current_etag = _g_local_file_info_create_etag (&original_stat);
837 if (strcmp (etag, current_etag) != 0)
839 g_set_error_literal (error,
841 G_IO_ERROR_WRONG_ETAG,
842 _("The file was externally modified"));
843 g_free (current_etag);
846 g_free (current_etag);
849 /* We use two backup strategies.
850 * The first one (which is faster) consist in saving to a
851 * tmp file then rename the original file to the backup and the
852 * tmp file to the original name. This is fast but doesn't work
853 * when the file is a link (hard or symbolic) or when we can't
854 * write to the current dir or can't set the permissions on the
856 * The second strategy consist simply in copying the old file
857 * to a backup file and rewrite the contents of the file.
860 if ((flags & G_FILE_CREATE_REPLACE_DESTINATION) ||
861 (!(original_stat.st_nlink > 1) && !is_symlink))
863 char *dirname, *tmp_filename;
866 dirname = g_path_get_dirname (filename);
867 tmp_filename = g_build_filename (dirname, ".goutputstream-XXXXXX", NULL);
870 tmpfd = g_mkstemp (tmp_filename);
873 g_free (tmp_filename);
874 goto fallback_strategy;
877 /* try to keep permissions (unless replacing) */
879 if ( ! (flags & G_FILE_CREATE_REPLACE_DESTINATION) &&
882 fchown (tmpfd, original_stat.st_uid, original_stat.st_gid) == -1 ||
885 fchmod (tmpfd, original_stat.st_mode) == -1 ||
891 struct stat tmp_statbuf;
893 /* Check that we really needed to change something */
894 if (fstat (tmpfd, &tmp_statbuf) != 0 ||
895 original_stat.st_uid != tmp_statbuf.st_uid ||
896 original_stat.st_gid != tmp_statbuf.st_gid ||
897 original_stat.st_mode != tmp_statbuf.st_mode)
900 g_unlink (tmp_filename);
901 g_free (tmp_filename);
902 goto fallback_strategy;
907 *temp_filename = tmp_filename;
915 #if defined(HAVE_FCHOWN) && defined(HAVE_FCHMOD)
916 struct stat tmp_statbuf;
918 char *backup_filename;
921 backup_filename = create_backup_filename (filename);
923 if (g_unlink (backup_filename) == -1 && errno != ENOENT)
925 g_set_error_literal (error,
927 G_IO_ERROR_CANT_CREATE_BACKUP,
928 _("Backup file creation failed"));
929 g_free (backup_filename);
933 bfd = g_open (backup_filename,
934 O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
935 original_stat.st_mode & 0777);
939 g_set_error_literal (error,
941 G_IO_ERROR_CANT_CREATE_BACKUP,
942 _("Backup file creation failed"));
943 g_free (backup_filename);
947 /* If needed, Try to set the group of the backup same as the
948 * original file. If this fails, set the protection
949 * bits for the group same as the protection bits for
951 #if defined(HAVE_FCHOWN) && defined(HAVE_FCHMOD)
952 if (fstat (bfd, &tmp_statbuf) != 0)
954 g_set_error_literal (error,
956 G_IO_ERROR_CANT_CREATE_BACKUP,
957 _("Backup file creation failed"));
958 g_unlink (backup_filename);
959 g_free (backup_filename);
963 if ((original_stat.st_gid != tmp_statbuf.st_gid) &&
964 fchown (bfd, (uid_t) -1, original_stat.st_gid) != 0)
967 (original_stat.st_mode & 0707) |
968 ((original_stat.st_mode & 07) << 3)) != 0)
970 g_set_error_literal (error,
972 G_IO_ERROR_CANT_CREATE_BACKUP,
973 _("Backup file creation failed"));
974 g_unlink (backup_filename);
976 g_free (backup_filename);
982 if (!copy_file_data (fd, bfd, NULL))
984 g_set_error_literal (error,
986 G_IO_ERROR_CANT_CREATE_BACKUP,
987 _("Backup file creation failed"));
988 g_unlink (backup_filename);
990 g_free (backup_filename);
996 g_free (backup_filename);
998 /* Seek back to the start of the file after the backup copy */
999 if (lseek (fd, 0, SEEK_SET) == -1)
1003 g_set_error (error, G_IO_ERROR,
1004 g_io_error_from_errno (errsv),
1005 _("Error seeking in file: %s"),
1006 g_strerror (errsv));
1011 if (flags & G_FILE_CREATE_REPLACE_DESTINATION)
1015 if (g_unlink (filename) != 0)
1019 g_set_error (error, G_IO_ERROR,
1020 g_io_error_from_errno (errsv),
1021 _("Error removing old file: %s"),
1022 g_strerror (errsv));
1027 open_flags = O_RDWR | O_CREAT | O_BINARY;
1029 open_flags = O_WRONLY | O_CREAT | O_BINARY;
1030 fd = g_open (filename, open_flags, mode);
1034 char *display_name = g_filename_display_name (filename);
1035 g_set_error (error, G_IO_ERROR,
1036 g_io_error_from_errno (errsv),
1037 _("Error opening file '%s': %s"),
1038 display_name, g_strerror (errsv));
1039 g_free (display_name);
1045 /* Truncate the file at the start */
1047 if (g_win32_ftruncate (fd, 0) == -1)
1049 if (ftruncate (fd, 0) == -1)
1054 g_set_error (error, G_IO_ERROR,
1055 g_io_error_from_errno (errsv),
1056 _("Error truncating file: %s"),
1057 g_strerror (errsv));
1071 _g_local_file_output_stream_replace (const char *filename,
1074 gboolean create_backup,
1075 GFileCreateFlags flags,
1076 GCancellable *cancellable,
1079 GLocalFileOutputStream *stream;
1083 gboolean sync_on_close;
1086 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1091 if (flags & G_FILE_CREATE_PRIVATE)
1095 sync_on_close = FALSE;
1097 /* If the file doesn't exist, create it */
1098 open_flags = O_CREAT | O_EXCL | O_BINARY;
1100 open_flags |= O_RDWR;
1102 open_flags |= O_WRONLY;
1103 fd = g_open (filename, open_flags, mode);
1105 if (fd == -1 && errno == EEXIST)
1107 /* The file already exists */
1108 fd = handle_overwrite_open (filename, readable, etag,
1109 create_backup, &temp_file,
1110 flags, cancellable, error);
1114 /* If the final destination exists, we want to sync the newly written
1115 * file to ensure the data is on disk when we rename over the destination.
1116 * otherwise if we get a system crash we can lose both the new and the
1117 * old file on some filesystems. (I.E. those that don't guarantee the
1118 * data is written to the disk before the metadata.)
1120 sync_on_close = TRUE;
1126 if (errsv == EINVAL)
1127 /* This must be an invalid filename, on e.g. FAT */
1128 g_set_error_literal (error, G_IO_ERROR,
1129 G_IO_ERROR_INVALID_FILENAME,
1130 _("Invalid filename"));
1133 char *display_name = g_filename_display_name (filename);
1134 g_set_error (error, G_IO_ERROR,
1135 g_io_error_from_errno (errsv),
1136 _("Error opening file '%s': %s"),
1137 display_name, g_strerror (errsv));
1138 g_free (display_name);
1144 stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
1145 stream->priv->fd = fd;
1146 stream->priv->sync_on_close = sync_on_close;
1147 stream->priv->tmp_filename = temp_file;
1149 stream->priv->backup_filename = create_backup_filename (filename);
1150 stream->priv->original_filename = g_strdup (filename);
1152 return G_FILE_OUTPUT_STREAM (stream);