...and here's the diff, which I forgot to attach the first time.  :P

On Jul 16, Matt Brubeck wrote:

> The attached patch makes GnuCash remember the original file permissions when
> available, and preserve them in the newly saved file.
Index: gnc-book.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-book.c,v
retrieving revision 1.41.2.1
diff -u -r1.41.2.1 gnc-book.c
--- src/engine/gnc-book.c       17 Jun 2001 07:34:45 -0000      1.41.2.1
+++ src/engine/gnc-book.c       16 Jul 2002 16:05:29 -0000
@@ -599,6 +599,8 @@
 {
   const gchar *datafile = gnc_book_get_file_path(book);
   char *tmp_name;
+  struct stat statbuf;
+  int rc;
 
   tmp_name = g_new(char, strlen(datafile) + 12);
   strcpy(tmp_name, datafile);
@@ -621,6 +623,22 @@
   
   if(gnc_book_write_to_xml_file_v2(book, tmp_name)) 
   {
+      /* Record the file's permissions before unlinking it */
+      rc = stat(datafile, &statbuf);
+      if(rc == 0)
+      {
+          /* Use the permissions from the original data file */
+          if(chmod(tmp_name, statbuf.st_mode) != 0)
+          {
+              gnc_book_push_error(
+                  book, ERR_BACKEND_MISC,
+                  g_strdup_printf("unable to chmod filename %s: %s",
+                                  datafile ? datafile : "(null)",
+                                  strerror(errno) ? strerror(errno) : ""));
+              g_free(tmp_name);
+              return FALSE;
+          }
+      }
       if(unlink(datafile) != 0 && errno != ENOENT)
       {
           gnc_book_push_error(

Reply via email to