[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: CVS update: f_basic.nw



  User: cnieves 
  Date: 06/02/25 09:42:02

  Modified:    .        f_basic.nw
  Log:
  Set the backup files readonly, so a "rm *" command will ask the user first.
  
  
  
  
  Revision  Changes    Path
  1.19      +34 -2     eda/geda/devel/libgeda/noweb/f_basic.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: f_basic.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/libgeda/noweb/f_basic.nw,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- f_basic.nw	27 Nov 2005 00:15:06 -0000	1.18
  +++ f_basic.nw	25 Feb 2006 14:42:01 -0000	1.19
  @@ -235,7 +235,15 @@
       o_net_consolidate(w_current);
     }
   
  +  if (load_backup_file == 0) {
  +    /* If it's not the backup file */
     w_current->page_current->CHANGED=0; /* added 4/7/98 */
  +  }
  +  else {
  +    /* We are loading the backup file, so gschem should ask
  +       the user if save it or not when closing the page. */
  +    w_current->page_current->CHANGED=1;
  +  }
   
     free(full_filename);
     free(full_rcfilename);
  @@ -304,7 +312,7 @@
     gchar *real_filename;
     gchar *only_filename;
     gchar *dirname;
  -  mode_t saved_umask;
  +  mode_t saved_umask, mask;
     struct stat st;
   
     /* Get the real filename and file permissions */
  @@ -327,10 +335,34 @@
       {
         backup_filename = g_strdup_printf("%s%c%s~", dirname, 
   					G_DIR_SEPARATOR, only_filename);
  +
  +      /* Make the backup file read-write before saving a new one */
  +      if ( g_file_test (backup_filename, G_FILE_TEST_EXISTS) && 
  +	   (! g_file_test (backup_filename, G_FILE_TEST_IS_DIR))) {
  +	if (chmod(backup_filename, S_IREAD|S_IWRITE) != 0) {
  +	  s_log_message ("Could NOT set previous backup file [%s] read-write\n", 
  +			 backup_filename);	    
  +	}
  +      }
  +	
         if (rename(real_filename, backup_filename) != 0) {
   	s_log_message ("Can't save backup file: %s.", backup_filename);
   	fprintf (stderr, "Can't save backup file: %s.", backup_filename);
         }
  +      else {
  +	/* Make the backup file readonly so a 'rm *' command will ask 
  +	   the user before deleting it */
  +	saved_umask = umask(0);
  +	mask = (S_IWRITE|S_IWGRP|S_IEXEC|S_IXGRP|S_IXOTH);
  +	mask = (~mask)&0777;
  +	mask &= ((~saved_umask) & 0777);
  +	if (chmod(backup_filename, mask) != 0) {
  +	  s_log_message ("Could NOT set backup file [%s] readonly\n", 
  +			   backup_filename);	    
  +	}
  +	umask(saved_umask);
  +      }
  +
         g_free(backup_filename);
       }
     }