~ubuntu-branches/ubuntu/jaunty/glib2.0/jaunty-updates

« back to all changes in this revision

Viewing changes to glib/gfileutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-04-10 12:02:08 UTC
  • mfrom: (1.2.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20090410120208-zz9zekvwg43ez8xg
Tags: 2.20.1-0ubuntu1
* New upstream version:
  - Bug fixes:
  575555 Use fsync() when replacing files to avoid data loss on
  575708 runaway inotify madness
  575270 GVolumeMonitor::mount-pre-unmount not being emitted
  577128 glib make check Failed to execute child process...
  573673 Always show "backup" directories
  578369 g_time_val_from_iso8601() parses timezones incorrectly
  578002 Fix a small typo in GFile docs
  578017 G_DEFINE_TYPE_EXTENDED docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
868
868
static gchar *
869
869
write_to_temp_file (const gchar  *contents,
870
870
                    gssize        length,
871
 
                    const gchar  *template,
 
871
                    const gchar  *dest_file,
872
872
                    GError      **err)
873
873
{
874
874
  gchar *tmp_name;
880
880
 
881
881
  retval = NULL;
882
882
  
883
 
  tmp_name = g_strdup_printf ("%s.XXXXXX", template);
 
883
  tmp_name = g_strdup_printf ("%s.XXXXXX", dest_file);
884
884
 
885
885
  errno = 0;
886
886
  fd = create_temp_file (tmp_name, 0666);
942
942
          goto out;
943
943
        }
944
944
    }
945
 
   
 
945
 
 
946
  errno = 0;
 
947
  if (fflush (file) != 0)
 
948
    { 
 
949
      save_errno = errno;
 
950
      
 
951
      g_set_error (err,
 
952
                   G_FILE_ERROR,
 
953
                   g_file_error_from_errno (save_errno),
 
954
                   _("Failed to write file '%s': fflush() failed: %s"),
 
955
                   display_name, 
 
956
                   g_strerror (save_errno));
 
957
 
 
958
      g_unlink (tmp_name);
 
959
      
 
960
      goto out;
 
961
    }
 
962
  
 
963
#ifdef HAVE_FSYNC
 
964
  errno = 0;
 
965
  /* If the final destination exists, we want to sync the newly written
 
966
   * file to ensure the data is on disk when we rename over the destination.
 
967
   * otherwise if we get a system crash we can lose both the new and the
 
968
   * old file on some filesystems. (I.E. those that don't guarantee the
 
969
   * data is written to the disk before the metadata.)
 
970
   */
 
971
  if (g_file_test (dest_file, G_FILE_TEST_EXISTS) &&
 
972
      fsync (fileno (file)) != 0)
 
973
    { 
 
974
      save_errno = errno;
 
975
      
 
976
      g_set_error (err,
 
977
                   G_FILE_ERROR,
 
978
                   g_file_error_from_errno (save_errno),
 
979
                   _("Failed to write file '%s': fsync() failed: %s"),
 
980
                   display_name, 
 
981
                   g_strerror (save_errno));
 
982
 
 
983
      g_unlink (tmp_name);
 
984
      
 
985
      goto out;
 
986
    }
 
987
#endif
 
988
  
946
989
  errno = 0;
947
990
  if (fclose (file) == EOF)
948
991
    { 
949
 
      save_errno = 0;
 
992
      save_errno = errno;
950
993
      
951
994
      g_set_error (err,
952
995
                   G_FILE_ERROR,