~ubuntu-branches/ubuntu/intrepid/gedit/intrepid-proposed

« back to all changes in this revision

Viewing changes to gedit/gedit-document-saver.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-07-04 15:15:07 UTC
  • mto: (2.1.2 lenny)
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20070704151507-1pqdkv92m58z9n2n
Tags: upstream-2.19.2
ImportĀ upstreamĀ versionĀ 2.19.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * list of people on the gedit Team.  
26
26
 * See the ChangeLog files for a list of changes. 
27
27
 *
28
 
 * $Id: gedit-document-saver.c 5320 2006-11-26 13:13:14Z sfre $
 
28
 * $Id: gedit-document-saver.c 5597 2007-04-15 10:17:48Z pterjan $
29
29
 */
30
30
 
31
31
#ifdef HAVE_CONFIG_H
620
620
                if (fchown (tmpfd, statbuf.st_uid, statbuf.st_gid) == -1 ||
621
621
                    fchmod (tmpfd, statbuf.st_mode) == -1)
622
622
                {
 
623
                        struct stat tmp_statbuf;
623
624
                        gedit_debug_message (DEBUG_SAVER, "could not set perms");
624
625
 
625
 
                        close (tmpfd);
626
 
                        unlink (tmp_filename);
627
 
                        g_free (tmp_filename);
 
626
                        /* Check that we really needed to change something */
 
627
                        if (fstat (saver->priv->fd, &tmp_statbuf) != 0 ||
 
628
                                        statbuf.st_uid != tmp_statbuf.st_uid ||
 
629
                                        statbuf.st_gid != tmp_statbuf.st_gid ||
 
630
                                        statbuf.st_mode != tmp_statbuf.st_mode)
 
631
                        {
 
632
                                close (tmpfd);
 
633
                                unlink (tmp_filename);
 
634
                                g_free (tmp_filename);
628
635
 
629
 
                        goto fallback_strategy;
 
636
                                goto fallback_strategy;
 
637
                        }
630
638
                }
631
639
 
632
640
                /* copy the xattrs, like user.mime_type, over. Also ACLs and
757
765
        if ((saver->priv->flags & GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP) == 0)
758
766
        {
759
767
                gint bfd;
 
768
                struct stat tmp_statbuf;
760
769
 
761
770
                gedit_debug_message (DEBUG_SAVER, "copying to backup");
762
771
 
794
803
                        goto out;
795
804
                }
796
805
 
797
 
                /* Try to set the group of the backup same as the
798
 
                 * original file. If this fails, set the protection
 
806
                if (fstat (saver->priv->fd, &tmp_statbuf) != 0)
 
807
                {
 
808
                        gedit_debug_message (DEBUG_SAVER, "could not stat the backup file");
 
809
 
 
810
                        g_set_error (&saver->priv->error,
 
811
                                     GEDIT_DOCUMENT_ERROR,
 
812
                                     GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
 
813
                                     "No backup created");
 
814
 
 
815
                        unlink (backup_filename);
 
816
                        close (bfd);
 
817
                        goto out;
 
818
                }
 
819
 
 
820
                /* If needed, Try to set the group of the backup same as
 
821
                 * the original file. If this fails, set the protection
799
822
                 * bits for the group same as the protection bits for
800
823
                 * others. */
801
 
                if (fchown (bfd, (uid_t) -1, statbuf.st_gid) != 0)
 
824
                if ((statbuf.st_gid != tmp_statbuf.st_gid) &&
 
825
                    fchown (bfd, (uid_t) -1, statbuf.st_gid) != 0)
802
826
                {
803
827
                        gedit_debug_message (DEBUG_SAVER, "could not restore group");
804
828