[Xfce4-commits] r25021 - in squeeze/trunk: libsqueeze tests/zip

Stephan Arts stephan at xfce.org
Fri Feb 23 16:17:41 CET 2007


Author: stephan
Date: 2007-02-23 15:17:41 +0000 (Fri, 23 Feb 2007)
New Revision: 25021

Modified:
   squeeze/trunk/libsqueeze/archive-command.c
   squeeze/trunk/libsqueeze/archive-command.h
   squeeze/trunk/libsqueeze/archive-support-gnu-tar.c
   squeeze/trunk/libsqueeze/archive-support-zip.c
   squeeze/trunk/tests/zip/test-add.c
   squeeze/trunk/tests/zip/test-extract.c
   squeeze/trunk/tests/zip/test-zip-add.pl
Log:
fix add of gnu-tar (tar.bz2 .tar.gz tested)

Modified: squeeze/trunk/libsqueeze/archive-command.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.c	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/libsqueeze/archive-command.c	2007-02-23 15:17:41 UTC (rev 25021)
@@ -178,20 +178,31 @@
 	gchar **argvp;
 	gint argcp;
 	gint fd_in, fd_out, fd_err;
+	gchar *escaped_archive_path;
 
 	g_return_val_if_fail(archive_command->child_pid == 0, FALSE);
 
 	const gchar *files = g_object_get_data(G_OBJECT(archive_command), "files");
 	const gchar *options = g_object_get_data(G_OBJECT(archive_command), "options");
+	const gchar *archive_path = g_object_get_data(G_OBJECT(archive_command), "archive");
 
 	if(files == NULL)
 		files = "";
 	if(options == NULL)
 		options = "";
-	gchar *archive_path = g_shell_quote(archive_command->archive->path);
-	gchar *command = g_strdup_printf(archive_command->command, archive_path, files, options);
+	
+	if(archive_path)
+	{
+		escaped_archive_path = g_shell_quote(archive_path);
+	}
+	else
+		escaped_archive_path = g_shell_quote(archive_command->archive->path);
 
+	gchar *command = g_strdup_printf(archive_command->command, escaped_archive_path, files, options);
+
+#ifdef DEBUG
 	g_debug("%s\n", command);
+#endif
 	g_shell_parse_argv(command, &argcp, &argvp, NULL);
 	if ( ! g_spawn_async_with_pipes (
 			NULL,
@@ -205,13 +216,15 @@
 			&fd_out,
 			&fd_err,
 			NULL) )
+	{
+		g_object_unref(archive_command);
 		return FALSE;
+	}
 
 	g_object_ref(archive_command);
 	g_child_watch_add(archive_command->child_pid, lsq_archive_command_child_watch_func, archive_command);
 
-	/* TODO: add iochannel_watches */
-	if(archive_command->parse_stdout)
+	if(archive_command->parse_stdout != NULL)
 	{
 		g_object_ref(archive_command);
 		archive_command->ioc_out = g_io_channel_unix_new(fd_out);
@@ -220,7 +233,7 @@
 		g_io_add_watch (archive_command->ioc_out, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL, lsq_archive_command_parse_stdout, archive_command);
 	}
 
-	g_free(archive_path);
+	g_free(escaped_archive_path);
 	g_free(command);
 	return TRUE;
 }
@@ -334,16 +347,31 @@
 }
 
 GIOStatus
-lsq_archive_command_read_line(LSQArchiveCommand *archive_command, guint fd, gchar **line, gsize *length)
+lsq_archive_command_read_line(LSQArchiveCommand *archive_command, guint fd, gchar **line, gsize *length, GError **error)
 {
 	GIOStatus status = G_IO_STATUS_EOF;
 	switch(fd)
 	{
 		case 1:
-			status = g_io_channel_read_line(archive_command->ioc_out, line, length, NULL, NULL);
+			status = g_io_channel_read_line(archive_command->ioc_out, line, length, NULL, error);
 			break;
 		default:
 			break;
 	}
 	return status;
 }
+
+GIOStatus
+lsq_archive_command_read_bytes(LSQArchiveCommand *archive_command, guint fd, gchar *buf, gsize max_length, gsize *length, GError **error)
+{
+	GIOStatus status = G_IO_STATUS_EOF;
+	switch(fd)
+	{
+		case 1:
+			status = g_io_channel_read_chars(archive_command->ioc_out, buf, max_length, length, error);
+			break;
+		default:
+			break;
+	}
+	return status;
+}

Modified: squeeze/trunk/libsqueeze/archive-command.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.h	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/libsqueeze/archive-command.h	2007-02-23 15:17:41 UTC (rev 25021)
@@ -74,8 +74,17 @@
 GIOStatus           lsq_archive_command_read_line(LSQArchiveCommand *archive_command,
                                                   guint fd,
                                                   gchar **lines,
-                                                  gsize *length) G_GNUC_INTERNAL;
+                                                  gsize *length,
+																									GError **error) G_GNUC_INTERNAL;
+GIOStatus           lsq_archive_command_read_bytes(LSQArchiveCommand *archive_command, 
+                                                  guint fd,
+                                                  gchar *buf,
+                                                  gsize max_length,
+                                                  gsize *length,
+                                                  GError **error) G_GNUC_INTERNAL;
+gboolean            lsq_archive_command_set_parse_func(LSQArchiveCommand *archive_command,
+                                                  guint fd,
+                                                  LSQParseFunc func);
 
 G_END_DECLS
-
 #endif /* __LIBSQUEEZE_ARCHIVE_COMMAND_H__ */

Modified: squeeze/trunk/libsqueeze/archive-support-gnu-tar.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-gnu-tar.c	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/libsqueeze/archive-support-gnu-tar.c	2007-02-23 15:17:41 UTC (rev 25021)
@@ -65,11 +65,11 @@
 lsq_archive_support_gnu_tar_class_init(LSQArchiveSupportGnuTarClass *supportclass);
 
 gboolean
-lsq_archive_support_gnu_tar_refresh_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data);
+lsq_archive_support_gnu_tar_refresh_parse_output(LSQArchiveCommand *archive_command);
 gboolean
-lsq_archive_support_gnu_tar_compress_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data);
+lsq_archive_support_gnu_tar_compress_parse_output(LSQArchiveCommand *archive_command);
 gboolean
-lsq_archive_support_gnu_tar_decompress_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data);
+lsq_archive_support_gnu_tar_decompress_parse_output(LSQArchiveCommand *archive_command);
 
 void
 lsq_archive_support_gnu_tar_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
@@ -298,11 +298,6 @@
 		}
 		else
 		{
-			if(g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-tar"))
-			{
-				gchar *tmp_file = g_strconcat(lsq_tmp_dir, "/squeeze-XXXXXX.tar" , NULL);
-				g_mkstemp(tmp_file);
-			}
 			if(!g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-tarz"))
 				command_skeleton = g_strdup("uncompress -c %1$s");
 			if(!g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-compressed-tar"))
@@ -314,12 +309,17 @@
 			if(command_skeleton)
 			{
 				archive_command = lsq_archive_command_new("", archive, command_skeleton, FALSE);
+				lsq_archive_command_set_parse_func(archive_command, 1, lsq_archive_support_gnu_tar_decompress_parse_output);
+				tmp_file = g_strconcat(lsq_tmp_dir, "/squeeze-XXXXXX.tar" , NULL);
+				g_mkstemp(tmp_file);
 				g_object_set_data(G_OBJECT(archive_command), LSQ_ARCHIVE_TEMP_FILE, tmp_file);
 				g_free(command_skeleton);
 			}
 
 			command_skeleton = g_strconcat(GNU_TAR_APP_NAME, " %3$s -r -f %1$s %2$s", NULL);
 			archive_command = lsq_archive_command_new("", archive, command_skeleton, FALSE);
+			if(tmp_file)
+				g_object_set_data(G_OBJECT(archive_command), "archive", g_strdup(tmp_file));
 			g_object_set_data(G_OBJECT(archive_command), "files", g_strdup(files));
 			g_object_set_data(G_OBJECT(archive_command), "options", g_strdup(options));
 			g_free(command_skeleton);
@@ -336,7 +336,10 @@
 			if(command_skeleton)
 			{
 				archive_command = lsq_archive_command_new("", archive, command_skeleton, FALSE);
-				g_object_set_data(G_OBJECT(archive_command), LSQ_ARCHIVE_TEMP_FILE, tmp_file);
+				lsq_archive_command_set_parse_func(archive_command, 1, lsq_archive_support_gnu_tar_compress_parse_output);
+				if(tmp_file)
+					g_object_set_data(G_OBJECT(archive_command), "archive", g_strdup(tmp_file));
+				g_object_set_data(G_OBJECT(archive_command), LSQ_ARCHIVE_TEMP_FILE, g_strdup(tmp_file));
 				g_free(command_skeleton);
 			}
 		}
@@ -372,7 +375,7 @@
 }
 
 gboolean
-lsq_archive_support_gnu_tar_refresh_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data)
+lsq_archive_support_gnu_tar_refresh_parse_output(LSQArchiveCommand *archive_command)
 {
 /*
 	GIOStatus status = G_IO_STATUS_NORMAL;
@@ -502,61 +505,71 @@
 }
 
 gboolean
-lsq_archive_support_gnu_tar_decompress_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data)
+lsq_archive_support_gnu_tar_decompress_parse_output(LSQArchiveCommand *archive_command)
 {
-	FILE *out_file = NULL;
-	LSQArchive *archive = data;
+	GIOStatus status = G_IO_STATUS_NORMAL;
 	gchar *buf = g_new0(gchar, 1024);
 	guint read = 0;
 	GError *error = NULL;
+	FILE *out_file;
 
-	const gchar *out_filename = g_object_get_data(G_OBJECT(archive), LSQ_ARCHIVE_TEMP_FILE);
+	const gchar *out_filename = g_object_get_data(G_OBJECT(archive_command), LSQ_ARCHIVE_TEMP_FILE);
 
-	if(cond & (G_IO_PRI | G_IO_IN))
+	out_file = fopen(out_filename, "ab");
+	if(!out_file)
+		return FALSE; 
+	
+	status = lsq_archive_command_read_bytes(archive_command, 1, buf, 1024, (gsize *)&read, &error);
+	if(status == G_IO_STATUS_EOF)
 	{
-		out_file = fopen(out_filename, "ab");
-		if(!out_file)
-			g_critical("Could not open file");
-
-		while(g_io_channel_read_chars(ioc, buf, 1024, (gsize *)&read, &error) == G_IO_STATUS_NORMAL)
-		{
-			if(read)
-			{
-				fwrite(buf, 1, read, out_file);
-			}
-			read = 0;
-		}
 		fclose(out_file);
+		return TRUE;
 	}
+
+	if(read)
+	{
+		fwrite(buf, 1, read, out_file);
+	}
+	fclose(out_file);
 	g_free(buf);
-	return FALSE;
+
+	return TRUE;
 }
 
 gboolean
-lsq_archive_support_gnu_tar_compress_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data)
+lsq_archive_support_gnu_tar_compress_parse_output(LSQArchiveCommand *archive_command)
 {
-	FILE *out_file = NULL;
-	LSQArchive *archive = data;
+	GIOStatus status = G_IO_STATUS_NORMAL;
 	gchar *buf = g_new0(gchar, 1024);
+	LSQArchive *archive = archive_command->archive;
 	guint read = 0;
 	GError *error = NULL;
+	FILE *out_file;
 
-	if(cond & (G_IO_PRI | G_IO_IN))
+	const gchar *out_filename = archive->path;
+	gboolean remove = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(archive_command), "compressing"));
+	if(remove == FALSE)
 	{
-		out_file = fopen(archive->path, "ab");
-		if(!out_file)
-			g_critical("Could not open file");
+		g_object_set_data(G_OBJECT(archive_command), "compressing", GUINT_TO_POINTER(TRUE));
+		g_unlink(out_filename);
+	}
 
-		while(g_io_channel_read_chars(ioc, buf, 1024, (gsize *)&read, &error) == G_IO_STATUS_NORMAL)
-		{
-			if(read)
-			{
-				fwrite(buf, 1, read, out_file);
-			}
-			read = 0;
-		}
+	out_file = fopen(out_filename, "ab");
+	if(!out_file)
+		return FALSE; 
+	
+	status = lsq_archive_command_read_bytes(archive_command, 1, buf, 1024, (gsize *)&read, &error);
+	if(status == G_IO_STATUS_EOF)
+	{
 		fclose(out_file);
+		return TRUE;
 	}
+
+	if(read)
+	{
+		fwrite(buf, 1, read, out_file);
+	}
+	fclose(out_file);
 	g_free(buf);
 	return FALSE;
 }

Modified: squeeze/trunk/libsqueeze/archive-support-zip.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-zip.c	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/libsqueeze/archive-support-zip.c	2007-02-23 15:17:41 UTC (rev 25021)
@@ -348,6 +348,7 @@
 			i++;
 		}
 		archive_command = lsq_archive_command_new("", archive, "unzip -lv -qq %1$s", TRUE);
+		lsq_archive_command_set_parse_func(archive_command, 1, lsq_archive_support_zip_refresh_parse_output);
 		lsq_archive_command_run(archive_command);
 		g_object_unref(archive_command);
 	}
@@ -369,7 +370,7 @@
 
 	LSQArchiveIter *entry;
 
-	status = lsq_archive_command_read_line(archive_command, 1, &line, &linesize);
+	status = lsq_archive_command_read_line(archive_command, 1, &line, &linesize, NULL);
 	if (line == NULL)
 	{
 		if(status == G_IO_STATUS_AGAIN)

Modified: squeeze/trunk/tests/zip/test-add.c
===================================================================
--- squeeze/trunk/tests/zip/test-add.c	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/tests/zip/test-add.c	2007-02-23 15:17:41 UTC (rev 25021)
@@ -22,14 +22,19 @@
 
 GMainLoop *loop = NULL;
 gint ret_val = 0;
-gchar *filename = NULL;
+gchar *n_filename = NULL;
+gchar *a_filename = NULL;
 
 static GOptionEntry entries[] =
 {
-	{	"new", 'n', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &filename,
+	{	"new", 'n', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &n_filename,
 		NULL,
 		NULL
 	},
+	{	"add", 'a', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &a_filename,
+		NULL,
+		NULL
+	},
 	{ NULL }
 };
 
@@ -62,13 +67,20 @@
 	g_option_context_add_main_entries(opt_context, entries, NULL);
 	g_option_context_parse (opt_context, &argc, &argv, NULL);
 
-	if(filename == NULL)
+	if(a_filename == NULL && n_filename == NULL)
 	{
 		g_print("Filename is not specified\n");
 		return 1;
 	}
 
-	lsq_new_archive(filename, TRUE, NULL, &archive);
+	if(n_filename)
+	{
+		lsq_new_archive(n_filename, TRUE, NULL, &archive);
+	}
+	if(a_filename && !archive) 
+	{
+		lsq_open_archive(a_filename, &archive);
+	}
 	archive_support = lsq_get_support_for_mimetype(lsq_archive_get_mimetype(archive));
 
 	g_signal_connect(G_OBJECT(archive), "command-terminated", G_CALLBACK(cb_command_terminated), NULL);

Modified: squeeze/trunk/tests/zip/test-extract.c
===================================================================
--- squeeze/trunk/tests/zip/test-extract.c	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/tests/zip/test-extract.c	2007-02-23 15:17:41 UTC (rev 25021)
@@ -1,4 +1,5 @@
 /*
+gchar *n_filename = NULL;
  *  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
  *  the Free Software Foundation; either version 2 of the License, or

Modified: squeeze/trunk/tests/zip/test-zip-add.pl
===================================================================
--- squeeze/trunk/tests/zip/test-zip-add.pl	2007-02-23 00:19:13 UTC (rev 25020)
+++ squeeze/trunk/tests/zip/test-zip-add.pl	2007-02-23 15:17:41 UTC (rev 25021)
@@ -7,7 +7,7 @@
 print "Target archive:\n";
 print "$test_archive\n";
 
- at args = ("./test-add", "-n", $test_archive, "$cwd/data/2.txt");
+ at args = ("./test-add", "-n", $test_archive, "$cwd/data/3.txt");
 system(@args) != 0
 	or die "system @args should fail: $?";
 



More information about the Xfce4-commits mailing list