file-roller r2428 - in trunk: . src



Author: paobac
Date: Sat Aug 16 10:49:34 2008
New Revision: 2428
URL: http://svn.gnome.org/viewvc/file-roller?rev=2428&view=rev

Log:
2008-08-16  Paolo Bacchilega  <paobac svn gnome org>

	* src/fr-command-tar.c: 
	* src/fr-command-7z.c: 
	* src/fr-archive.c: 
	
	Fixed creation of 7zip compressed tar archives (#547727).


Modified:
   trunk/ChangeLog
   trunk/src/fr-archive.c
   trunk/src/fr-command-7z.c
   trunk/src/fr-command-tar.c

Modified: trunk/src/fr-archive.c
==============================================================================
--- trunk/src/fr-archive.c	(original)
+++ trunk/src/fr-archive.c	Sat Aug 16 10:49:34 2008
@@ -580,36 +580,13 @@
 
 
 static gboolean
-create_command_from_mime_type (FrArchive  *archive,
-			       const char *mime_type,
-			       gboolean    loading)
-{
-	FrCommandCaps  requested_capabilities = FR_COMMAND_CAN_DO_NOTHING;
-	GType          command_type;
-	char          *filename;
-
-	if (mime_type == NULL)
-		return FALSE;
-
-	archive->is_compressed_file = FALSE;
-
-	/* try with the WRITE capability even when loading, this way we give
-	 * priority to the commands that can read and write over commands
-	 * that can only read a specific file format. */
-
-	requested_capabilities |= FR_COMMAND_CAN_READ_WRITE;
-	if (! loading && ! archive->can_create_compressed_file)
-		requested_capabilities |= FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
-	command_type = get_command_type_from_mime_type (mime_type, requested_capabilities);
-
-	/* if no command was found and we are loading, remove the write
-	 * capability and try again */
-
-	if ((command_type == 0) && loading) {
-		requested_capabilities ^= FR_COMMAND_CAN_WRITE;
-		command_type = get_command_type_from_mime_type (mime_type, requested_capabilities);
-	}
-
+create_command_from_type (FrArchive     *archive,
+			  const char    *mime_type,
+		          GType          command_type,
+		          FrCommandCaps  requested_capabilities)
+{
+	char *filename;
+	
 	if (command_type == 0)
 		return FALSE;
 
@@ -624,14 +601,66 @@
 	if (! fr_command_is_capable_of (archive->command, requested_capabilities)) {
 		g_object_unref (archive->command);
 		archive->command = NULL;
+		archive->is_compressed_file = FALSE;
 	}
-	else if (archive->command != NULL)
+	else 
 		archive->is_compressed_file = ! fr_command_is_capable_of (archive->command, FR_COMMAND_CAN_ARCHIVE_MANY_FILES);
 
 	return (archive->command != NULL);
 }
 
 
+static gboolean
+create_command_to_load_archive (FrArchive  *archive,
+			        const char *mime_type)
+{
+	FrCommandCaps requested_capabilities = FR_COMMAND_CAN_DO_NOTHING;
+	GType         command_type;
+
+	if (mime_type == NULL)
+		return FALSE;
+
+	/* try with the WRITE capability even when loading, this way we give
+	 * priority to the commands that can read and write over commands
+	 * that can only read a specific file format. */
+
+	requested_capabilities |= FR_COMMAND_CAN_READ_WRITE;
+	command_type = get_command_type_from_mime_type (mime_type, requested_capabilities);
+
+	/* if no command was found, remove the write capability and try again */
+
+	if (command_type == 0) {
+		requested_capabilities ^= FR_COMMAND_CAN_WRITE;
+		command_type = get_command_type_from_mime_type (mime_type, requested_capabilities);
+	}	
+
+	return create_command_from_type (archive,
+					 mime_type, 
+					 command_type, 
+					 requested_capabilities);
+}
+
+
+static gboolean
+create_command_to_create_archive (FrArchive  *archive,
+			          const char *mime_type)
+{
+	FrCommandCaps requested_capabilities = FR_COMMAND_CAN_DO_NOTHING;
+	GType         command_type;
+
+	if (mime_type == NULL)
+		return FALSE;
+
+	requested_capabilities |= FR_COMMAND_CAN_WRITE;
+	command_type = get_command_type_from_mime_type (mime_type, requested_capabilities);
+
+	return create_command_from_type (archive,
+					 mime_type, 
+					 command_type, 
+					 requested_capabilities);
+}
+
+
 static void
 action_started (FrCommand *command,
 		FrAction   action,
@@ -1042,7 +1071,7 @@
 	tmp_command = archive->command;
 
 	mime_type = get_mime_type_from_filename (archive->local_copy);
-	if (! create_command_from_mime_type (archive, mime_type, FALSE)) {
+	if (! create_command_to_create_archive (archive, mime_type)) {
 		archive->command = tmp_command;
 		return FALSE;
 	}
@@ -1096,11 +1125,11 @@
 	tmp_command = archive->command;
 
 	mime_type = get_mime_type_from_filename (archive->local_copy);
-	if (! create_command_from_mime_type (archive, mime_type, TRUE)) {
+	if (! create_command_to_load_archive (archive, mime_type)) {
 		mime_type = get_mime_type_from_content (archive->local_copy);
-		if (! create_command_from_mime_type (archive, mime_type, TRUE)) {
+		if (! create_command_to_load_archive (archive, mime_type)) {
 			mime_type = get_mime_type_from_magic_numbers (archive->local_copy);
-			if (! create_command_from_mime_type (archive, mime_type, TRUE)) {
+			if (! create_command_to_load_archive (archive, mime_type)) {
 				archive->command = tmp_command;
 				fr_archive_action_completed (archive,
 							     FR_ACTION_LOADING_ARCHIVE,
@@ -1598,8 +1627,7 @@
 
 	archive->command->creating_archive = ! g_file_test (archive->command->filename, G_FILE_TEST_EXISTS);
 	
-	if (! archive->command->creating_archive)
-		fr_command_uncompress (archive->command);
+	fr_command_uncompress (archive->command);
 
 	/* when files are already present in a tar archive and are added
 	 * again, they are not replaced, so we have to delete them first. */
@@ -1696,8 +1724,7 @@
 	path_list_free (new_file_list);
 
 	if (! error_occurred) {
-		if (! archive->command->creating_archive)
-			fr_command_recompress (archive->command);
+		fr_command_recompress (archive->command);
 
 		if (base_dir_created) { /* remove the temp dir */
 			fr_process_begin_command (archive->process, "rm");

Modified: trunk/src/fr-command-7z.c
==============================================================================
--- trunk/src/fr-command-7z.c	(original)
+++ trunk/src/fr-command-7z.c	Sat Aug 16 10:49:34 2008
@@ -507,6 +507,9 @@
 	if (is_mime_type (mime_type, "application/x-7z-compressed")) {
 		capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER | FR_COMMAND_CAN_CREATE_VOLUMES;
 	}
+	else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
+		capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER | FR_COMMAND_CAN_CREATE_VOLUMES;
+	}
 	else if (is_program_in_path ("7z")) {
 		if (is_mime_type (mime_type, "application/x-rar")
 		    || is_mime_type (mime_type, "application/x-cbr")) 

Modified: trunk/src/fr-command-tar.c
==============================================================================
--- trunk/src/fr-command-tar.c	(original)
+++ trunk/src/fr-command-tar.c	Sat Aug 16 10:49:34 2008
@@ -254,6 +254,13 @@
 }
 
 
+static gboolean
+can_create_a_compressed_archive (FrCommand *comm)
+{
+	return comm->creating_archive && ! is_mime_type (comm->mime_type, "application/x-7z-compressed-tar");
+}
+
+
 static void
 process_line__generic (char     *line,
 		       gpointer  data,
@@ -315,13 +322,16 @@
 		fr_process_add_arg (comm->process, base_dir);
 	}
 
-	if (comm->creating_archive) {
+	if (can_create_a_compressed_archive (comm)) {
 		fr_process_add_arg (comm->process, "-cf");
 		fr_process_add_arg (comm->process, comm->filename);
 		add_compress_arg (comm);
 	}
 	else {
-		fr_process_add_arg (comm->process, "-rf");
+		if (comm->creating_archive)
+			fr_process_add_arg (comm->process, "-cf");
+		else
+			fr_process_add_arg (comm->process, "-rf");
 		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
 	}
 
@@ -461,11 +471,14 @@
 
 
 static void
-fr_command_tar_recompress (FrCommand     *comm)
+fr_command_tar_recompress (FrCommand *comm)
 {
 	FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
 	char         *new_name = NULL;
 
+	if (can_create_a_compressed_archive (comm))
+		return;
+
 	if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
 		fr_process_begin_command (comm->process, "gzip");
 		fr_process_set_sticky (comm->process, TRUE);
@@ -721,6 +734,9 @@
 	char         *tmp_name;
 	gboolean      archive_exists;
 
+	if (can_create_a_compressed_archive (comm))
+		return;
+
 	if (c_tar->uncomp_filename != NULL) {
 		g_free (c_tar->uncomp_filename);
 		c_tar->uncomp_filename = NULL;
@@ -822,14 +838,14 @@
 }
 
 
-const char *tar_mime_types[] = { "application/x-tar",
-			   "application/x-compressed-tar",
-			   "application/x-bzip-compressed-tar",
-			   "application/x-tarz",
-			   "application/x-lzma-compressed-tar",
-			   "application/x-lzop-compressed-tar",
-			   "application/x-7z-compressed-tar",
-			   NULL };
+const char *tar_mime_types[] = { "application/x-compressed-tar",
+				 "application/x-bzip-compressed-tar",
+				 "application/x-tar",
+				 "application/x-7z-compressed-tar",
+			         "application/x-lzma-compressed-tar",
+			         "application/x-lzop-compressed-tar",		         
+			         "application/x-tarz",
+			         NULL };
 
 
 const char **
@@ -882,7 +898,7 @@
 
 		for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
 			if (is_program_in_path (try_command[i])) {
-				capabilities |= FR_COMMAND_CAN_READ_WRITE;
+				capabilities |= FR_COMMAND_CAN_WRITE;
 				break;
 			}
 		}



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