All pastes #25249 Raw Edit

Something

public text v1 · immutable
#25249 ·published 2005-10-11 17:32 UTC
rendered paste body
 
+	if (error)
+		*error = err;
+

Forse devi usare g_propagate_error, ma dal contesto non si capisce bene

 	return ret;
 }
 
@@ -513,6 +517,16 @@ save_existing_local_file (GeditDocumentS
 
 	/* prepare the backup name */
 	backup_filename = get_backup_filename (saver);
+	if (backup_filename == NULL)
+	{
+		/* bad bad luck... */
+		g_set_error (&saver->priv->error,
+			     GEDIT_DOCUMENT_ERROR,
+			     GNOME_VFS_ERROR_GENERIC,
+			     gnome_vfs_result_to_string (GNOME_VFS_ERROR_GENERIC));
+
+		goto out;
+	}

In quali casi backup_filename potrebbe essere NULL?
Magari metti un warning con g_warning

 
 	/* We now use two backup strategies.
 	 * The first one (which is faster) consist in saving to a
@@ -636,58 +650,72 @@ save_existing_local_file (GeditDocumentS
 
  fallback_strategy:
 
-	/* move away old backups */
-	if (!remove_file (backup_filename))
+	/* try to copy the old contents in a backup for safety
+	 * unless we are explicetely told not to.
+	 */
+	if ((saver->priv->flags & GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP) == 0)
 	{
-		GnomeVFSResult result = gnome_vfs_result_from_errno ();
+		/* move away old backups */
+		if (!remove_file (backup_filename))
+		{
+			/* we don't care about which was the problem, just
+			 * that a backup was not possible.
+			 */
+			g_set_error (&saver->priv->error,
+				     GEDIT_DOCUMENT_ERROR,
+				     GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
+				     "No backup created");

potrebbe essere interessante sapere il perchè non si è potuto creare il backup.
Magari _abusa_ del campo testo per mettere il codice dell'errore.

-		g_set_error (&saver->priv->error,
-			     GEDIT_DOCUMENT_ERROR,
-			     result,
-			     gnome_vfs_result_to_string (result));
+			goto out;
+		}
 
-		goto out;
-	}
+		bfd = open (backup_filename,
+			    O_WRONLY | O_CREAT | O_EXCL,
+			    statbuf.st_mode & 0777);

Sono sempre confuso da umask & C. In pratica con quali permessi è creato il file di backup (e dove?)
Io direi che dovrebbe essere sola lettura per l'utente e niente per gli altri.

-	bfd = open (backup_filename,
-		    O_WRONLY | O_CREAT | O_EXCL,
-		    statbuf.st_mode & 0777);
+		if (bfd == -1)
+		{
+			g_set_error (&saver->priv->error,
+				     GEDIT_DOCUMENT_ERROR,
+				     GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
+				     "No backup created");

Vedi sopra per codice errore.

-	if (bfd == -1)
-	{
-		GnomeVFSResult result = gnome_vfs_result_from_errno ();
+			goto out;
+		}
 
-		g_set_error (&saver->priv->error,
-			     GEDIT_DOCUMENT_ERROR,
-			     result,
-			     gnome_vfs_result_to_string (result));
+		/* Try to set the group of the backup same as the
+		 * original file. If this fails, set the protection
+		 * bits for the group same as the protection bits for
+		 * others. */

Sei sicuro che sia "sicuro"?

+		if (fchown (bfd, (uid_t) -1, statbuf.st_gid) != 0)
+		{
+			if (fchmod (bfd,
+			            (statbuf.st_mode& 0707) |
+			            ((statbuf.st_mode & 07) << 3)) != 0)
+			{
+				g_set_error (&saver->priv->error,
+					     GEDIT_DOCUMENT_ERROR,
+					     GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
+					     "No backup created");

Vedi sopra per codice errore.

+		if (!copy_file_data (saver->priv->fd, bfd, NULL))
 		{
-			GnomeVFSResult result = gnome_vfs_result_from_errno ();
+				g_set_error (&saver->priv->error,
+					     GEDIT_DOCUMENT_ERROR,
+					     GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
+					     "No backup created");

Vedi sopra per codice errore.
 
 typedef enum
 {
-	GEDIT_DOCUMENT_SAVE_IGNORE_MTIME	 = 1 << 0,
-	GEDIT_DOCUMENT_SAVE_IGNORE_NOBACKUP	 = 1 << 1
+	/* save file despite external modifications */
+	GEDIT_DOCUMENT_SAVE_IGNORE_MTIME 	= 1 << 0,
+
+	/* try to save anyway even if a prior backup was not possible */

You mean: Save without backup in any case.

+	GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP	= 1 << 1
 } GeditDocumentSaveFlags;

 
 
@@ -122,6 +125,7 @@ enum
 	 * for the error codes */ 
 	GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED = GNOME_VFS_NUM_ERRORS,
 	GEDIT_DOCUMENT_ERROR_NOT_REGULAR_FILE,
+	GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
 	GEDIT_DOCUMENT_NUM_ERRORS 
 };