[file-roller] fixed error when renaming a file in rar/arj/lhz archives
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller] fixed error when renaming a file in rar/arj/lhz archives
- Date: Sun, 25 Nov 2012 14:39:16 +0000 (UTC)
commit 308ab89a33ddf4b0396ce5dc1eb33eb84b8a1b18
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Nov 25 15:31:52 2012 +0100
fixed error when renaming a file in rar/arj/lhz archives
if the command deletes the archive when deleting all the files inside the
the archive an error occurs when the file/folder to rename is the single
top-level element.
src/fr-archive.c | 1 +
src/fr-archive.h | 8 +++++
src/fr-command-arj.c | 1 +
src/fr-command-lha.c | 1 +
src/fr-command-rar.c | 1 +
src/fr-command.c | 78 +++++++++++++++++++++++++++++++++++++-------------
6 files changed, 70 insertions(+), 20 deletions(-)
---
diff --git a/src/fr-archive.c b/src/fr-archive.c
index 66e46e9..410757d 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -457,6 +457,7 @@ fr_archive_init (FrArchive *self)
self->propTest = FALSE;
self->propCanExtractAll = TRUE;
self->propCanDeleteNonEmptyFolders = TRUE;
+ self->propCanDeleteAllFiles = TRUE;
self->propCanExtractNonEmptyFolders = TRUE;
self->propListFromFile = FALSE;
diff --git a/src/fr-archive.h b/src/fr-archive.h
index 9a9d4eb..64866d1 100644
--- a/src/fr-archive.h
+++ b/src/fr-archive.h
@@ -167,6 +167,14 @@ struct _FrArchive {
*/
guint propCanDeleteNonEmptyFolders : 1;
+ /* propCanDeleteAllFiles:
+ *
+ * TRUE if the command does not delete the archive itself if all the
+ * files in the archive are deleted.
+ */
+
+ guint propCanDeleteAllFiles : 1;
+
/* propCanExtractNonEmptyFolders:
*
* is used to overcome an issue with tar. For example if
diff --git a/src/fr-command-arj.c b/src/fr-command-arj.c
index 808ff88..e696be2 100644
--- a/src/fr-command-arj.c
+++ b/src/fr-command-arj.c
@@ -397,6 +397,7 @@ fr_command_arj_init (FrCommandArj *self)
base->propExtractCanAvoidOverwrite = TRUE;
base->propExtractCanSkipOlder = TRUE;
base->propExtractCanJunkPaths = TRUE;
+ base->propCanDeleteAllFiles = FALSE;
base->propPassword = TRUE;
base->propTest = TRUE;
diff --git a/src/fr-command-lha.c b/src/fr-command-lha.c
index c4f6c91..77bd4a8 100644
--- a/src/fr-command-lha.c
+++ b/src/fr-command-lha.c
@@ -375,6 +375,7 @@ fr_command_lha_init (FrCommandLha *self)
base->propExtractCanAvoidOverwrite = FALSE;
base->propExtractCanSkipOlder = FALSE;
base->propExtractCanJunkPaths = TRUE;
+ base->propCanDeleteAllFiles = FALSE;
base->propPassword = FALSE;
base->propTest = FALSE;
}
diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c
index ba58304..628a1d3 100644
--- a/src/fr-command-rar.c
+++ b/src/fr-command-rar.c
@@ -678,6 +678,7 @@ fr_command_rar_init (FrCommandRar *self)
base->propExtractCanAvoidOverwrite = TRUE;
base->propExtractCanSkipOlder = TRUE;
base->propExtractCanJunkPaths = TRUE;
+ base->propCanDeleteAllFiles = FALSE;
base->propPassword = TRUE;
base->propTest = TRUE;
base->propListFromFile = TRUE;
diff --git a/src/fr-command.c b/src/fr-command.c
index 49d3669..992c57e 100644
--- a/src/fr-command.c
+++ b/src/fr-command.c
@@ -1029,6 +1029,7 @@ _fr_command_add (FrCommand *self,
for (scan = new_file_list; scan != NULL; scan = scan->next) {
char *filename = scan->data;
+
if (find_file_in_archive (archive, filename))
del_list = g_list_prepend (del_list, filename);
}
@@ -2444,6 +2445,38 @@ fr_command_test_integrity (FrArchive *archive,
static void
+fr_command_rename__delete (FrArchive *archive,
+ GList **file_list,
+ gboolean is_dir,
+ gboolean dir_in_archive,
+ const char *original_path)
+{
+ FrCommand *self = FR_COMMAND (archive);
+ gboolean added_dir;
+
+ /* temporarily add the dir to rename to the list if it's stored in the
+ * archive, this way it will be removed from the archive... */
+ added_dir = FALSE;
+ if (is_dir && dir_in_archive && ! g_list_find_custom (*file_list, original_path, (GCompareFunc) strcmp)) {
+ *file_list = g_list_prepend (*file_list, g_strdup (original_path));
+ added_dir = TRUE;
+ }
+
+ _fr_command_remove (self, *file_list, archive->compression);
+
+ /* ...and remove it from the list again */
+ if (added_dir) {
+ GList *tmp;
+
+ tmp = *file_list;
+ *file_list = g_list_remove_link (*file_list, tmp);
+
+ _g_string_list_free (tmp);
+ }
+}
+
+
+static void
fr_command_rename (FrArchive *archive,
GList *file_list,
const char *old_name,
@@ -2458,7 +2491,6 @@ fr_command_rename (FrArchive *archive,
{
FrCommand *self = FR_COMMAND (archive);
GFile *tmp_dir;
- gboolean added_dir;
char *new_dirname;
GList *new_file_list;
GList *scan;
@@ -2473,6 +2505,9 @@ fr_command_rename (FrArchive *archive,
tmp_dir = _g_file_get_temp_work_dir (NULL);
fr_process_clear (self->process);
+
+ /* extract the files to rename */
+
_fr_command_extract (self,
file_list,
tmp_dir,
@@ -2482,26 +2517,17 @@ fr_command_rename (FrArchive *archive,
FALSE,
archive->password);
- /* temporarily add the dir to rename to the list if it's stored in the
- * archive, this way it will be removed from the archive... */
- added_dir = FALSE;
- if (is_dir && dir_in_archive && ! g_list_find_custom (file_list, original_path, (GCompareFunc) strcmp)) {
- file_list = g_list_prepend (file_list, g_strdup (original_path));
- added_dir = TRUE;
- }
+ /* if the command can delete all the files in the archive without
+ * deleting the archive itself ('rar' deletes the archive), delete the
+ * files here, that is before adding the renamed files to the archive,
+ * to make the operation faster. */
- _fr_command_remove (self, file_list, archive->compression);
-
- /* ...and remove it from the list again */
- if (added_dir) {
- GList *tmp;
-
- tmp = file_list;
- file_list = g_list_remove_link (file_list, tmp);
-
- g_free (tmp->data);
- g_list_free (tmp);
- }
+ if (archive->propCanDeleteAllFiles)
+ fr_command_rename__delete (archive,
+ &file_list,
+ is_dir,
+ dir_in_archive,
+ original_path);
/* rename the files. */
@@ -2594,6 +2620,17 @@ fr_command_rename (FrArchive *archive,
g_free (new_dirname);
_g_string_list_free (new_file_list);
+ /* if the command cannot delete all the files in the archive without
+ * deleting the archive itself ('rar' deletes the archive), delete
+ * the old files here to avoid a potential error. */
+
+ if (! archive->propCanDeleteAllFiles)
+ fr_command_rename__delete (archive,
+ &file_list,
+ is_dir,
+ dir_in_archive,
+ original_path);
+
/* remove the tmp dir */
fr_process_begin_command (self->process, "rm");
@@ -2658,6 +2695,7 @@ fr_command_paste_clipboard (FrArchive *archive,
&& (old_name[strlen (old_name) - 1] != '/'))
{
fr_process_begin_command (command->process, "mv");
+ fr_process_set_ignore_error (command->process, TRUE);
fr_process_set_working_dir_file (command->process, tmp_dir);
fr_process_add_arg (command->process, "-f");
if (old_name[0] == '/')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]