[Xfce4-commits] r22651 - xarchiver/trunk/src
Giuseppe Torelli
colossus at xfce.org
Fri Aug 4 13:09:18 UTC 2006
Author: colossus
Date: 2006-08-04 13:09:17 +0000 (Fri, 04 Aug 2006)
New Revision: 22651
Modified:
xarchiver/trunk/src/archive.h
xarchiver/trunk/src/callbacks.c
xarchiver/trunk/src/callbacks.h
xarchiver/trunk/src/extract_dialog.c
xarchiver/trunk/src/extract_dialog.h
Log:
Changed the code for handling extraction with no path for tar archives.
Fixed a bug with detection of zip and arj encrypted archives introduced with revision 22638.
Modified: xarchiver/trunk/src/archive.h
===================================================================
--- xarchiver/trunk/src/archive.h 2006-08-04 13:02:53 UTC (rev 22650)
+++ xarchiver/trunk/src/archive.h 2006-08-04 13:09:17 UTC (rev 22651)
@@ -66,7 +66,6 @@
gboolean solid_archive;
gboolean remove_files;
unsigned short int compression_level;
- unsigned short int tar_strip_value;
gchar *passwd;
gint nr_of_files;
gint nr_of_dirs;
Modified: xarchiver/trunk/src/callbacks.c
===================================================================
--- xarchiver/trunk/src/callbacks.c 2006-08-04 13:02:53 UTC (rev 22650)
+++ xarchiver/trunk/src/callbacks.c 2006-08-04 13:09:17 UTC (rev 22651)
@@ -917,6 +917,8 @@
unsigned int extended_header_CRC;
unsigned char arj_flag;
+ fseek ( stream, 0 , SEEK_SET );
+ fseek ( stream, 6 , SEEK_SET );
if ( type == XARCHIVETYPE_ZIP )
{
while ( memcmp ( magic,"\x50\x4b\x03\x04",4 ) == 0 || memcmp ( magic,"\x50\x4b\x05\x06",4 ) == 0 )
@@ -1160,6 +1162,12 @@
archive->full_path = 0;
archive->overwrite = 1;
+ gtk_tree_model_get (model, &iter, 0, &dummy_name, -1);
+ dir = EscapeBadChars ( dummy_name , 1 );
+ names = g_string_new (" ");
+ g_string_append ( names , dir );
+ archive->parse_output = 0;
+
if (archive->type == XARCHIVETYPE_ISO)
{
gtk_tree_model_get (model, &iter,
@@ -1172,25 +1180,31 @@
ViewFileFromArchive (archive->child_pid , 0 , name);
g_free (permissions);
}
+ else if (archive->type == XARCHIVETYPE_TAR || archive->type == XARCHIVETYPE_TAR_BZ2 || archive->type == XARCHIVETYPE_TAR_GZ)
+ {
+ gchar *option = NULL;
+ gchar *digit;
+ digit = g_strdup_printf ("%d", CountCharacter (names->str , '/') );
+ if (archive->type == XARCHIVETYPE_TAR)
+ option = " -xvf ";
+ else if (archive->type == XARCHIVETYPE_TAR_BZ2)
+ option = " -xvjf ";
+ else if (archive->type == XARCHIVETYPE_TAR_GZ)
+ option = " -xvzf ";
+ command = g_strconcat ("tar --strip-components=",digit,option,archive->escaped_path," -C /tmp",names->str,NULL);
+ g_free (digit);
+ }
else
- {
- gtk_tree_model_get (model, &iter, 0, &dummy_name, -1);
- dir = EscapeBadChars ( dummy_name , 1 );
- names = g_string_new (" ");
- g_string_append ( names , dir );
-
- archive->parse_output = 0;
command = xa_extract_single_files ( archive , names, "/tmp");
- SpawnAsyncProcess ( archive , command , 0, 0);
- g_free ( command );
- g_string_free (names,TRUE);
+ SpawnAsyncProcess ( archive , command , 0, 0);
+ g_free (command);
+ if ( archive->child_pid == 0 )
+ return;
- if ( archive->child_pid == 0 )
- return;
- g_child_watch_add ( archive->child_pid , (GChildWatchFunc) ViewFileFromArchive , dummy_name );
- }
- archive->full_path = full_path;
- archive->overwrite = overwrite;
+ g_string_free (names,TRUE);
+ g_child_watch_add ( archive->child_pid , (GChildWatchFunc) ViewFileFromArchive , dummy_name );
+ archive->full_path = full_path;
+ archive->overwrite = overwrite;
}
GChildWatchFunc *ViewFileFromArchive (GPid pid , gint status , gchar *data)
@@ -1563,7 +1577,7 @@
g_free (name);
}
-void xa_run_command ( gchar *command , gboolean watch_child_flag )
+gboolean xa_run_command ( gchar *command , gboolean watch_child_flag )
{
int status;
gboolean waiting = TRUE;
@@ -1573,7 +1587,7 @@
archive->parse_output = 0;
SpawnAsyncProcess ( archive , command , 0, 1);
if ( archive->child_pid == 0 )
- return;
+ return FALSE;
gtk_widget_show ( viewport2 );
while (waiting)
@@ -1587,6 +1601,7 @@
}
if (watch_child_flag)
xa_watch_child (archive->child_pid, status, archive);
+ return TRUE;
}
void Update_StatusBar ( gchar *msg)
@@ -1800,7 +1815,6 @@
gtk_tree_model_get (model, &iter, 0, &name, -1);
extract_path = extract_local_path ( no_uri_path , name );
- archive->tar_strip_value = CountCharacter ( name, '/' );
g_free (name);
g_free ( no_uri_path );
if (extract_path != NULL)
Modified: xarchiver/trunk/src/callbacks.h
===================================================================
--- xarchiver/trunk/src/callbacks.h 2006-08-04 13:02:53 UTC (rev 22650)
+++ xarchiver/trunk/src/callbacks.h 2006-08-04 13:09:17 UTC (rev 22651)
@@ -115,7 +115,7 @@
void ConcatenateFileNames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data);
void ConcatenateFileNames2 (gchar *filename , GString *data);
void xa_cat_filenames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data);
-void xa_run_command ( gchar *command , gboolean watch_child_flag );
+gboolean xa_run_command ( gchar *command , gboolean watch_child_flag );
void OffDeleteandViewButtons();
void OffTooltipPadlock();
void Update_StatusBar (gchar *msg);
Modified: xarchiver/trunk/src/extract_dialog.c
===================================================================
--- xarchiver/trunk/src/extract_dialog.c 2006-08-04 13:02:53 UTC (rev 22650)
+++ xarchiver/trunk/src/extract_dialog.c 2006-08-04 13:09:17 UTC (rev 22651)
@@ -23,7 +23,6 @@
#include "callbacks.h"
#include "support.h"
-gchar *strip_string = NULL;
gboolean ISO_stop_flag = FALSE;
Extract_dialog_data *xa_create_extract_dialog (gint selected , XArchive *archive)
@@ -153,14 +152,11 @@
gtk_widget_show (dialog_data->overwrite_check);
gtk_box_pack_start (GTK_BOX (dialog_data->vbox4), dialog_data->overwrite_check, FALSE, FALSE, 0);
- if (archive->type == XARCHIVETYPE_RAR || archive->type == XARCHIVETYPE_ZIP || archive->type == XARCHIVETYPE_ARJ || archive->type == XARCHIVETYPE_7ZIP || archive->type == XARCHIVETYPE_ISO)
- {
- dialog_data->extract_full = gtk_check_button_new_with_mnemonic (_("Extract files with full path"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog_data->extract_full), archive->full_path);
- gtk_widget_show (dialog_data->extract_full);
- gtk_tooltips_set_tip (dialog_data->option_tooltip,dialog_data->extract_full , _("The archive's directory structure is recreated in the extraction directory."), NULL );
- gtk_box_pack_start (GTK_BOX (dialog_data->vbox4), dialog_data->extract_full, FALSE, FALSE, 0);
- }
+ dialog_data->extract_full = gtk_check_button_new_with_mnemonic (_("Extract files with full path"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog_data->extract_full), archive->full_path);
+ gtk_widget_show (dialog_data->extract_full);
+ gtk_tooltips_set_tip (dialog_data->option_tooltip,dialog_data->extract_full , _("The archive's directory structure is recreated in the extraction directory."), NULL );
+ gtk_box_pack_start (GTK_BOX (dialog_data->vbox4), dialog_data->extract_full, FALSE, FALSE, 0);
if (archive->type == XARCHIVETYPE_TAR || archive->type == XARCHIVETYPE_TAR_GZ || archive->type == XARCHIVETYPE_TAR_BZ2)
{
@@ -174,29 +170,6 @@
gtk_widget_show (dialog_data->hbox6);
gtk_box_pack_start (GTK_BOX (dialog_data->vbox4), dialog_data->hbox6, FALSE, FALSE, 0);
- dialog_data->strip = gtk_check_button_new_with_mnemonic (_("Strip directories:"));
- gtk_widget_show (dialog_data->strip);
- gtk_box_pack_start (GTK_BOX (dialog_data->hbox6), dialog_data->strip, FALSE, FALSE, 0);
- gtk_tooltips_set_tip (dialog_data->option_tooltip,dialog_data->strip , _("This option extracts the files without the directory in which they are contained. You have to specify the number of directories to strip."), NULL );
-
- dialog_data->strip_entry = gtk_entry_new ();
- gtk_widget_set_size_request (dialog_data->strip_entry, 24, -1);
- gtk_entry_set_max_length (GTK_ENTRY (dialog_data->strip_entry), 2);
-
- if ( ! archive->full_path )
- {
- gchar *strip_text;
- strip_text = g_strdup_printf ( "%d",archive->tar_strip_value);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog_data->strip), TRUE);
- gtk_entry_set_text (GTK_ENTRY (dialog_data->strip_entry), strip_text );
- g_free (strip_text);
- gtk_widget_set_sensitive (dialog_data->strip_entry , TRUE);
- }
- else
- gtk_widget_set_sensitive (dialog_data->strip_entry , FALSE);
- gtk_widget_show (dialog_data->strip_entry);
- gtk_box_pack_start (GTK_BOX (dialog_data->hbox6), dialog_data->strip_entry, FALSE, FALSE, 0);
- g_signal_connect ( (gpointer) dialog_data->strip, "toggled", G_CALLBACK (show_hide_strip_entry) , dialog_data );
}
else
dialog_data->touch = NULL;
@@ -297,15 +270,6 @@
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->fresh), FALSE);
}
-void show_hide_strip_entry (GtkToggleButton *button, Extract_dialog_data *data)
-{
- gboolean active = FALSE;
- if (gtk_toggle_button_get_active (button) )
- active = TRUE;
- gtk_widget_set_sensitive (data->strip_entry, active);
- gtk_widget_grab_focus (data->strip_entry);
-}
-
gchar *xa_parse_extract_dialog_options ( XArchive *archive , Extract_dialog_data *dialog_data, GtkTreeSelection *selection)
{
gchar *command = NULL;
@@ -370,23 +334,8 @@
if ( dialog_data->touch != NULL)
archive->tar_touch = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( dialog_data->touch ));
- if ( dialog_data->strip != NULL)
- {
- archive->full_path = ! gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( dialog_data->strip ));
- archive->tar_strip_value = atoi (gtk_entry_get_text (GTK_ENTRY(dialog_data->strip_entry)) );
- gchar *digit;
- digit = g_strdup_printf ("%d", archive->tar_strip_value );
- strip_string = g_strconcat ( "--strip-components=" , digit , " " , NULL );
- g_free (digit);
- }
- else
- {
- if (dialog_data->extract_full != NULL)
- {
- archive->full_path = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( dialog_data->extract_full ));
- archive->tar_strip_value = 0;
- }
- }
+ if (dialog_data->extract_full != NULL)
+ archive->full_path = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( dialog_data->extract_full ));
if (dialog_data->fresh != NULL)
archive->freshen = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( dialog_data->fresh ));
@@ -423,27 +372,48 @@
break;
case XARCHIVETYPE_TAR:
- command = g_strconcat (tar, " ",archive->full_path ? "" : strip_string,
- "-xvf ", archive->escaped_path,
+ if (archive->full_path == 1)
+ {
+ command = g_strconcat (tar, " -xvf ", archive->escaped_path,
archive->overwrite ? " --overwrite" : " --keep-old-files",
archive->tar_touch ? " --touch" : "",
" -C " , extract_path , NULL );
+ }
+ else
+ {
+ xa_extract_tar_without_directories ( "tar -xvf " , archive->escaped_path, archive->overwrite,archive->tar_touch,extract_path );
+ command = NULL;
+ }
break;
case XARCHIVETYPE_TAR_BZ2:
- command = g_strconcat (tar, " ",archive->full_path ? "" : strip_string,
- "-xvjf " , archive->escaped_path,
+ if (archive->full_path == 1)
+ {
+ command = g_strconcat (tar, " -xvjf " , archive->escaped_path,
archive->overwrite ? " --overwrite" : " --keep-old-files",
archive->tar_touch ? " --touch" : "",
" -C " , extract_path , NULL );
+ }
+ else
+ {
+ xa_extract_tar_without_directories ( "tar -xvjf " , archive->escaped_path, archive->overwrite,archive->tar_touch,extract_path );
+ command = NULL;
+ }
break;
case XARCHIVETYPE_TAR_GZ:
- command = g_strconcat (tar, " ",archive->full_path ? "" : strip_string,
- "-xvzf " , archive->escaped_path,
+ if (archive->full_path == 1)
+ {
+ command = g_strconcat (tar, " -xvzf " , archive->escaped_path,
archive->overwrite ? " --overwrite" : " --keep-old-files",
archive->tar_touch ? " --touch" : "",
" -C " , extract_path , NULL );
+ }
+ else
+ {
+ xa_extract_tar_without_directories ( "tar -xvzf " , archive->escaped_path, archive->overwrite,archive->tar_touch,extract_path );
+ command = NULL;
+ }
break;
case XARCHIVETYPE_ZIP:
@@ -550,15 +520,7 @@
gchar *command;
gchar *tar;
- if ( archive->full_path == 0)
- {
- archive->tar_strip_value = CountCharacter ( files->str , '/');
- gchar *digit;
- digit = g_strdup_printf ( "%d" , archive->tar_strip_value );
- strip_string = g_strconcat ( "--strip-components=" , digit , " " , NULL );
- g_free (digit);
- }
- gchar *msg = g_strdup_printf( _("Extracting files to %s") , path);
+ gchar *msg = g_strdup_printf( _("Extracting archive to %s") , path);
Update_StatusBar (msg);
g_free (msg);
tar = g_find_program_in_path ("gtar");
@@ -583,27 +545,48 @@
break;
case XARCHIVETYPE_TAR:
- command = g_strconcat (tar, " ",archive->full_path ? "" : strip_string,
- "-xvf " , archive->escaped_path,
+ if (archive->full_path == 1)
+ {
+ command = g_strconcat (tar, " -xvf " , archive->escaped_path,
archive->overwrite ? " --overwrite" : " --keep-old-files",
archive->tar_touch ? " --touch" : "",
" -C " , path , files->str , NULL );
+ }
+ else
+ {
+ xa_extract_tar_without_directories ( "tar -xvf " , archive->escaped_path, archive->overwrite,archive->tar_touch,path );
+ command = NULL;
+ }
break;
case XARCHIVETYPE_TAR_BZ2:
- command = g_strconcat (tar, " ",archive->full_path ? "" : strip_string,
- "-xjvf " , archive->escaped_path,
+ if (archive->full_path == 1)
+ {
+ command = g_strconcat (tar, " -xjvf " , archive->escaped_path,
archive->overwrite ? " --overwrite" : " --keep-old-files",
archive->tar_touch ? " --touch" : "",
" -C " , path , files->str , NULL );
+ }
+ else
+ {
+ xa_extract_tar_without_directories ( "tar -xjvf " , archive->escaped_path, archive->overwrite,archive->tar_touch,path );
+ command = NULL;
+ }
break;
case XARCHIVETYPE_TAR_GZ:
- command = g_strconcat (tar, " ",archive->full_path ? "" : strip_string,
- "-xzvf " , archive->escaped_path,
+ if (archive->full_path == 1)
+ {
+ command = g_strconcat (tar, " -xzvf " , archive->escaped_path,
archive->overwrite ? " --overwrite" : " --keep-old-files",
archive->tar_touch ? " --touch" : "",
" -C " , path , files->str , NULL );
+ }
+ else
+ {
+ xa_extract_tar_without_directories ( "tar -xzvf " , archive->escaped_path, archive->overwrite,archive->tar_touch,path );
+ command = NULL;
+ }
break;
case XARCHIVETYPE_ZIP:
@@ -695,11 +678,81 @@
command = NULL;
}
g_free (tar);
- if ( strip_string != NULL)
+ return command;
+}
+
+gboolean xa_extract_tar_without_directories ( gchar *string, gchar *escaped_path, gboolean overwrite, gboolean tar_touch, gchar *extract_path )
+{
+ gchar tmp_dir[14];
+ gchar *command = NULL;
+ gchar *name = NULL;
+ gchar *permission = NULL;
+ GtkTreeSelection *selection;
+ GString *names;
+ gboolean end = FALSE;
+ GtkTreeIter iter;
+ GList *row_list;
+
+ names = g_string_new ("");
+ selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (treeview1) );
+ row_list = gtk_tree_selection_get_selected_rows (selection, &model);
+
+ if (row_list != NULL)
{
- g_free ( strip_string );
- strip_string = NULL;
+ while (row_list)
+ {
+ gtk_tree_model_get_iter(model, &iter, row_list->data);
+ gtk_tree_model_get (model, &iter,
+ 0, &name,
+ 1, &permission,
+ -1);
+ gtk_tree_path_free (row_list->data);
+
+ if (strstr (permission ,"d") == NULL)
+ ConcatenateFileNames2 ( name , names );
+ g_free (permission);
+ row_list = row_list->next;
+ }
+ g_list_free (row_list);
}
- return command;
+ else
+ {
+ end = gtk_tree_model_get_iter_first (model , &iter);
+ while (end)
+ {
+ gtk_tree_model_get (model, &iter, 0, &name,
+ 1, &permission, -1);
+ if (strstr (permission ,"d") == NULL)
+ ConcatenateFileNames2 ( name , names );
+ g_free (permission);
+ end = gtk_tree_model_iter_next (model,&iter);
+ }
+ }
+
+ strcpy (tmp_dir,"/tmp/xa-XXXXXX");
+ if ( mkdtemp ( tmp_dir ) == 0)
+ {
+ response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't create temporary directory in /tmp:"),g_strerror(errno) );
+ return FALSE;
+ }
+ chdir (tmp_dir);
+
+ archive->tmp = g_strdup (tmp_dir);
+ command = g_strconcat ( string, escaped_path,
+ overwrite ? " --overwrite" : " --keep-old-files",
+ tar_touch ? " --touch" : "",
+ " -C " , tmp_dir , names->str, NULL );
+ xa_run_command (command , 0);
+ g_free (command);
+
+ command = g_strconcat ( "mv -f ", names->str, " " , extract_path , NULL );
+ xa_run_command (command , 0);
+ g_free (command);
+
+ command = g_strconcat ( "rm -rf ", tmp_dir , NULL );
+ xa_run_command (command , 1);
+ g_free (command);
+
+ g_string_free (names, TRUE);
+ return TRUE;
}
-
Modified: xarchiver/trunk/src/extract_dialog.h
===================================================================
--- xarchiver/trunk/src/extract_dialog.h 2006-08-04 13:02:53 UTC (rev 22650)
+++ xarchiver/trunk/src/extract_dialog.h 2006-08-04 13:09:17 UTC (rev 22651)
@@ -49,8 +49,6 @@
GtkWidget *touch;
GtkWidget *fresh;
GtkWidget *update;
- GtkWidget *strip;
- GtkWidget *strip_entry;
GtkWidget *hbox5;
GtkWidget *hbox6;
GtkWidget *label_password;
@@ -68,9 +66,8 @@
Extract_dialog_data *xa_create_extract_dialog (gint selected ,XArchive *archive);
void fresh_update_toggled_cb (GtkToggleButton *button, Extract_dialog_data *data);
void update_fresh_toggled_cb (GtkToggleButton *button, Extract_dialog_data *data);
-void show_hide_strip_entry (GtkToggleButton *button, Extract_dialog_data *data);
gchar *xa_parse_extract_dialog_options ( XArchive *archive , Extract_dialog_data *dialog_data, GtkTreeSelection *selection);
gchar *xa_extract_single_files ( XArchive *archive , GString *files, gchar *path);
-
+gboolean xa_extract_tar_without_directories ( gchar *string, gchar *escaped_path, gboolean overwrite, gboolean tar_touch, gchar *extract_path );
#endif
More information about the Xfce4-commits
mailing list