Author: colossus
Date: 2007-09-25 07:46:29 +0000 (Tue, 25 Sep 2007)
New Revision: 26107
Modified:
xarchiver/trunk/src/bzip2.c
xarchiver/trunk/src/bzip2.h
xarchiver/trunk/src/rpm.c
xarchiver/trunk/src/rpm.h
xarchiver/trunk/src/string_utils.c
xarchiver/trunk/src/window.c
Log:
Fixed bug #3542; many thanks to Diego Ongaro for suggesting cpio --file option.
Code cleanup in bzip2.h, rpm.c and rpm.h.
Archive properties works for bzip2 archives too.
Removed unnecessary code in remove_level_from_path because of
g_path_get_dirname().
Modified: xarchiver/trunk/src/bzip2.c
===================================================================
--- xarchiver/trunk/src/bzip2.c 2007-09-25 02:34:54 UTC (rev 26106)
+++ xarchiver/trunk/src/bzip2.c 2007-09-25 07:46:29 UTC (rev 26107)
@@ -39,7 +39,7 @@
gchar *filename = NULL;;
gchar *_filename;
gchar *tar;
- gpointer item[3];
+ gpointer item[2];
unsigned short int i;
gboolean result;
@@ -78,16 +78,19 @@
}
else
{
- archive->has_properties = archive->can_add = archive->has_test
= archive->has_sfx = FALSE;
- archive->can_extract = TRUE;
- archive->nc = 3;
+ archive->can_add = archive->has_test = archive->has_sfx = FALSE;
+ archive->has_properties = archive->can_extract = TRUE;
+ archive->nc = 2;
+ archive->nr_of_files = 1;
+ archive->nr_of_dirs = 0;
+ archive->format = "BZIP2";
- GType types[]=
{G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING};
+ GType types[]=
{G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64};
archive->column_types = g_malloc0(sizeof(types));
- for (i = 0; i < 5; i++)
+ for (i = 0; i < 4; i++)
archive->column_types[i] = types[i];
- char *names[]= {(_("Compressed")),(_("Size")),(_("Modification
Date"))};
+ char *names[]= {(_("Compressed")),(_("Size"))};
xa_create_liststore (archive,names);
result = xa_create_temp_directory (tmp_dir);
if (result == 0)
@@ -105,10 +108,20 @@
Update_StatusBar (_("Operation canceled."));
return;
}
+
+ /* Let's get its compressed file size */
+ stat (archive->escaped_path,&my_stat);
+ compressed = g_strdup_printf("%lld",(unsigned long long
int)my_stat.st_size);
+ item[0] = compressed;
+
/* Let's extract it */
chdir (archive->tmp);
_filename = g_strrstr (archive->escaped_path , "/");
- command = g_strconcat("bzip2 -f -d
",archive->tmp,_filename,NULL);
+ if (_filename)
+ command = g_strconcat("bzip2 -f -d
",archive->tmp,_filename,NULL);
+ else
+ command = g_strconcat("bzip2 -f -d
",archive->tmp,"/",archive->escaped_path,NULL);
+
result = xa_run_command (archive,command,1);
g_free (command);
if (!result)
@@ -118,19 +131,23 @@
Update_StatusBar (_("Operation canceled."));
return;
}
- /* Let's get its compressed file size */
- stat (archive->escaped_path,&my_stat);
- compressed = g_strdup_printf("%lld",(unsigned long long
int)my_stat.st_size);
- item[0] = compressed;
- item[2] = ctime(&my_stat.st_mtime);
- /* and its uncompressed file size */
- _filename++;
- filename = g_strndup(_filename,strlen(_filename)-4);
- command = g_strconcat(archive->tmp,"/",filename,NULL);
+ /* and let's get its uncompressed file size */
+ if (_filename)
+ {
+ _filename++;
+ filename = g_strndup(_filename,strlen(_filename)-4);
+ command = g_strconcat(archive->tmp,"/",filename,NULL);
+ }
+ else
+ {
+ command =
g_strconcat(archive->tmp,"/",archive->escaped_path,NULL);
+ filename = g_strdup(archive->escaped_path);
+ }
stat (command,&my_stat);
g_free(command);
size = g_strdup_printf("%lld",(unsigned long long
int)my_stat.st_size);
+ archive->dummy_size = my_stat.st_size;
item[1] = size;
entry = xa_set_archive_entries_for_each_row
(archive,filename,FALSE,item);
@@ -144,7 +161,7 @@
}
}
-void gzip_bzip2_extract ( XArchive *archive , gboolean flag )
+void gzip_bzip2_extract (XArchive *archive , gboolean flag )
{
gchar *text = NULL;
gchar *filename_only = NULL;
Modified: xarchiver/trunk/src/bzip2.h
===================================================================
--- xarchiver/trunk/src/bzip2.h 2007-09-25 02:34:54 UTC (rev 26106)
+++ xarchiver/trunk/src/bzip2.h 2007-09-25 07:46:29 UTC (rev 26107)
@@ -27,6 +27,4 @@
void xa_open_bzip2 (XArchive *archive);
void gzip_bzip2_extract ( XArchive *archive , gboolean flag );
void xa_add_delete_tar_bzip2_gzip ( GString *list , XArchive *archive ,
gboolean dummy , gboolean add );
-GChildWatchFunc *AddToTar (GPid pid,gint status , gpointer data);
-gboolean file_extension_is (const char *filename, const char *ext);
#endif
Modified: xarchiver/trunk/src/rpm.c
===================================================================
--- xarchiver/trunk/src/rpm.c 2007-09-25 02:34:54 UTC (rev 26106)
+++ xarchiver/trunk/src/rpm.c 2007-09-25 07:46:29 UTC (rev 26107)
@@ -1,6 +1,5 @@
/*
- * Copyright (C) 2006 Giuseppe Torelli - <[EMAIL PROTECTED]>
- * Copyright (C) 2006 Benedikt Meurer - <[EMAIL PROTECTED]>
+ * Copyright (C) 2007 Giuseppe Torelli - <[EMAIL PROTECTED]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,18 +21,15 @@
#include "string_utils.h"
FILE *stream;
-gchar *cpio_tmp , *gzip_tmp = NULL;
+gchar *cpio_tmp,*gzip_tmp = NULL;
gchar tmp_dir[14] = "";
-gchar buffer[2048];
-gsize bytes_read = 0;
-gsize bytes_written = 0;
GIOStatus status;
gboolean result;
GError *error = NULL;
-GIOChannel *ioc_cpio,*input_ioc;
+GIOChannel *ioc_cpio;
void xa_get_cpio_line_content (gchar *line, gpointer data);
-void OpenRPM (XArchive *archive)
+void xa_open_rpm (XArchive *archive)
{
unsigned char bytes[8];
unsigned short int i;
@@ -124,10 +120,11 @@
xa_open_temp_file ( tmp_dir,gzip_tmp );
}
-GChildWatchFunc *OpenCPIO (GPid pid , gint exit_code , gpointer data)
+GChildWatchFunc *xa_open_cpio (GPid pid , gint exit_code , gpointer data)
{
gint current_page;
gint idx;
+ gchar *command;
current_page = gtk_notebook_get_current_page(notebook);
idx = xa_find_archive_index (current_page);
@@ -152,69 +149,21 @@
}
}
- /* Now I have to read the CPIO temp file and send its content to the
- * command cpio -tv so to receive its output in the
xa_get_cpio_line_content() */
-
+ command = g_strconcat ("cpio -tv --file ",gzip,NULL);
+ g_free(gzip);
archive[idx]->parse_output = xa_get_cpio_line_content;
- xa_spawn_async_process ( archive[idx] , "cpio -tv" , 1);
+ xa_spawn_async_process ( archive[idx],command,1);
+ g_free(command);
if ( archive[idx]->child_pid == 0 )
{
xa_delete_temp_directory (archive[idx],1);
g_free ( cpio_tmp );
return FALSE;
}
- ioc_cpio = g_io_channel_new_file (gzip,"r",NULL);
- g_free (gzip);
- g_io_channel_set_encoding (ioc_cpio,NULL,NULL);
- g_io_channel_set_flags (ioc_cpio,G_IO_FLAG_NONBLOCK,NULL);
- input_ioc = g_io_channel_unix_new ( archive[idx]->input_fd );
- g_io_add_watch (input_ioc, G_IO_IN|G_IO_OUT|G_IO_PRI, WriteCPIOInput,
archive[idx] );
- g_io_channel_set_encoding (input_ioc,NULL,NULL);
-
- g_child_watch_add (archive[idx]->child_pid, (GChildWatchFunc)
xa_watch_child, archive[idx]);
-
return NULL;
}
-/* input pipe */
-gboolean WriteCPIOInput (GIOChannel *ioc, GIOCondition cond, gpointer data)
-{
- XArchive *archive = data;
-
- if (cond & (G_IO_IN | G_IO_PRI | G_IO_OUT) )
- {
- /* Doing so I write to the input pipe of the spawned "cpio -tv"
so to output the list of files in the cpio archive */
- status = g_io_channel_read_chars (ioc_cpio,buffer,
sizeof(buffer), &bytes_read, NULL);
- if (status != G_IO_STATUS_EOF)
- {
- status = g_io_channel_write_chars
(ioc,buffer,bytes_read, &bytes_written, &error);
- if (status == G_IO_STATUS_ERROR)
- {
- response = xa_show_message_dialog (GTK_WINDOW
(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("An error
occurred:"),error->message);
- g_error_free (error);
- xa_delete_temp_directory (archive,1);
- CloseChannels (ioc_cpio);
- CloseChannels (ioc);
- return FALSE;
- }
- /*while ( bytes_read != bytes_written )
- status = g_io_channel_write_chars (ioc,buffer +
bytes_written,bytes_read - bytes_written,&bytes_written,&error);*/
-
- g_io_channel_flush (ioc,NULL);
- return TRUE;
- }
- else
- {
- CloseChannels (ioc_cpio);
- CloseChannels (ioc);
- return FALSE;
- }
- }
- return TRUE;
-}
-
-/* output pipe */
void xa_get_cpio_line_content (gchar *line, gpointer data)
{
XArchive *archive = data;
@@ -304,12 +253,6 @@
g_free (filename);
}
-void CloseChannels (GIOChannel *ioc)
-{
- g_io_channel_shutdown ( ioc,TRUE,NULL );
- g_io_channel_unref (ioc);
-}
-
void xa_open_temp_file (gchar *tmp_dir,gchar *temp_path)
{
gint current_page;
@@ -329,10 +272,11 @@
g_free (tmp);
return;
}
- if (xa_detect_archive_type ( temp_path ) == XARCHIVETYPE_GZIP)
- command = g_strconcat ( "gzip -dc " , temp_path , NULL );
+ if (xa_detect_archive_type (temp_path) == XARCHIVETYPE_GZIP)
+ command = g_strconcat ("gzip -dc ",temp_path,NULL);
else
- command = g_strconcat ( "bzip2 -dc " , temp_path , NULL );
+ command = g_strconcat ("bzip2 -dc ",temp_path,NULL);
+
archive[idx]->parse_output = 0;
xa_spawn_async_process (archive[idx],command,0);
g_free (command);
@@ -343,12 +287,12 @@
g_free (tmp);
return;
}
- GIOChannel *ioc = g_io_channel_unix_new ( archive[idx]->output_fd );
- g_io_channel_set_encoding (ioc, NULL , NULL);
- g_io_channel_set_flags ( ioc , G_IO_FLAG_NONBLOCK , NULL );
- g_io_add_watch (ioc, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
ExtractToDifferentLocation, stream);
+ GIOChannel *ioc = g_io_channel_unix_new (archive[idx]->output_fd);
+ g_io_channel_set_encoding (ioc,NULL,NULL);
+ g_io_channel_set_flags (ioc,G_IO_FLAG_NONBLOCK,NULL);
+ g_io_add_watch
(ioc,G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,ExtractToDifferentLocation,stream);
- g_child_watch_add ( archive[idx]->child_pid , (GChildWatchFunc)
OpenCPIO , tmp );
+ g_child_watch_add (archive[idx]->child_pid ,(GChildWatchFunc)
xa_open_cpio,tmp);
}
gboolean ExtractToDifferentLocation (GIOChannel *ioc, GIOCondition cond,
gpointer data)
Modified: xarchiver/trunk/src/rpm.h
===================================================================
--- xarchiver/trunk/src/rpm.h 2007-09-25 02:34:54 UTC (rev 26106)
+++ xarchiver/trunk/src/rpm.h 2007-09-25 07:46:29 UTC (rev 26107)
@@ -24,10 +24,7 @@
#include "interface.h"
#include "archive.h"
-void OpenRPM ( XArchive *archive );
-GChildWatchFunc *OpenCPIO (GPid pid , gint status , gpointer data);
-gboolean WriteCPIOInput (GIOChannel *ioc, GIOCondition cond, gpointer data);
-void CloseChannels ( GIOChannel *ioc );
+void xa_open_rpm ( XArchive *archive );
gboolean ExtractToDifferentLocation (GIOChannel *ioc, GIOCondition cond ,
gpointer data);
void xa_open_temp_file (gchar *tmp_dir,gchar *temp_path);
Modified: xarchiver/trunk/src/string_utils.c
===================================================================
--- xarchiver/trunk/src/string_utils.c 2007-09-25 02:34:54 UTC (rev 26106)
+++ xarchiver/trunk/src/string_utils.c 2007-09-25 07:46:29 UTC (rev 26107)
@@ -239,17 +239,7 @@
gchar *remove_level_from_path (const gchar *path)
{
- const gchar *ptr = path;
- gint p;
-
- if (! path) return NULL;
- p = strlen (path) - 1;
- if (p < 0) return NULL;
- while ((ptr[p] != '/') && (p > 0))
- p--;
- if ((p == 0) && (ptr[p] == '/'))
- p++;
- return g_strndup (path, (guint)p);
+ return g_path_get_dirname(path);
}
gboolean file_extension_is (const char *filename, const char *ext)
Modified: xarchiver/trunk/src/window.c
===================================================================
--- xarchiver/trunk/src/window.c 2007-09-25 02:34:54 UTC (rev 26106)
+++ xarchiver/trunk/src/window.c 2007-09-25 07:46:29 UTC (rev 26107)
@@ -353,7 +353,7 @@
break;
case XARCHIVETYPE_RPM:
- OpenRPM (archive[current_page]);
+ xa_open_rpm (archive[current_page]);
break;
case XARCHIVETYPE_TAR:
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits