[Xfce4-commits] r24950 - squeeze/trunk/libsqueeze

Stephan Arts stephan at xfce.org
Mon Feb 12 01:01:47 CET 2007


Author: stephan
Date: 2007-02-12 00:01:46 +0000 (Mon, 12 Feb 2007)
New Revision: 24950

Modified:
   squeeze/trunk/libsqueeze/archive-command.c
   squeeze/trunk/libsqueeze/archive-command.h
   squeeze/trunk/libsqueeze/archive-iter.c
   squeeze/trunk/libsqueeze/archive-iter.h
   squeeze/trunk/libsqueeze/archive-support-compr.c
   squeeze/trunk/libsqueeze/archive-support-compr.h
   squeeze/trunk/libsqueeze/archive-support-gnu-tar.c
   squeeze/trunk/libsqueeze/archive-support-gnu-tar.h
   squeeze/trunk/libsqueeze/archive-support-rar.c
   squeeze/trunk/libsqueeze/archive-support-rar.h
   squeeze/trunk/libsqueeze/archive-support-zip.c
   squeeze/trunk/libsqueeze/archive-support-zip.h
   squeeze/trunk/libsqueeze/archive-support.c
   squeeze/trunk/libsqueeze/archive-support.h
   squeeze/trunk/libsqueeze/archive-tempfs.c
   squeeze/trunk/libsqueeze/archive-tempfs.h
   squeeze/trunk/libsqueeze/internals.c
   squeeze/trunk/libsqueeze/internals.h
   squeeze/trunk/libsqueeze/libsqueeze.c
   squeeze/trunk/libsqueeze/libsqueeze.h
   squeeze/trunk/libsqueeze/slist.c
   squeeze/trunk/libsqueeze/slist.h
Log:
Added stdout watch interface to archive_command



Modified: squeeze/trunk/libsqueeze/archive-command.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-command.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -36,6 +36,12 @@
 static void
 lsq_archive_command_dispose(GObject *object);
 
+void
+lsq_archive_command_child_watch_func(GPid pid, gint status, gpointer data);
+
+gboolean
+lsq_archive_command_parse_stdout(GIOChannel *ioc, GIOCondition cond, gpointer data);
+
 //static gint lsq_archive_command_signals[0];
 
 static GObjectClass *parent_class;
@@ -93,6 +99,9 @@
 {
 	LSQArchiveCommand *archive_command = LSQ_ARCHIVE_COMMAND(object);
 	lsq_archive_dequeue_command(archive_command->archive, archive_command);
+
+	LSQArchiveCommand *next_archive_command = lsq_archive_get_front_command(archive_command->archive);
+	lsq_archive_command_run(next_archive_command);
 }
 
 /**
@@ -100,6 +109,7 @@
  * @comment: a description, describing what the command does
  * @archive: the archive the command modifies
  * @command: a formatted string defining the command to be executed.
+ * @safe: is it safe to terminate this child premature?
  *
  *
  * %%1$s is the application to be executed.
@@ -109,7 +119,7 @@
  * Returns: a new LSQArchiveCommand object
  */
 LSQArchiveCommand *
-lsq_archive_command_new(const gchar *comment, LSQArchive *archive, const gchar *command)
+lsq_archive_command_new(const gchar *comment, LSQArchive *archive, const gchar *command, gboolean safe)
 {
 	LSQArchiveCommand *archive_command;
 
@@ -117,6 +127,7 @@
 
 	archive_command->command = g_strdup(command);
 	archive_command->archive = archive;
+	archive_command->safe = safe;
 
 	lsq_archive_enqueue_command(archive, archive_command);
 
@@ -126,12 +137,18 @@
 /**
  * lsq_archive_command_run:
  * @archive_command: the archive_command to be run
- * 
+ *
  * Returns: true on success
  */
 gboolean
 lsq_archive_command_run(LSQArchiveCommand *archive_command)
 {
+	gchar **argvp;
+	gint argcp;
+	gint fd_in, fd_out, fd_err;
+
+	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");
 
@@ -139,16 +156,83 @@
 		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);
 
-	gchar *command = g_strdup_printf(archive_command->command, archive_command->archive->path, files, options);
 
+	g_shell_parse_argv(command, &argcp, &argvp, NULL);
+	if ( ! g_spawn_async_with_pipes (
+			NULL,
+			argvp,
+			NULL,
+			G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+			NULL,
+			NULL,
+			&(archive_command->child_pid),
+			&fd_in,
+			&fd_out,
+			&fd_err,
+			NULL) )
+		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)
+	{
+		g_object_ref(archive_command);
+		archive_command->ioc_out = g_io_channel_unix_new(fd_out);
+		g_io_channel_set_encoding (archive_command->ioc_out, NULL, NULL);
+		g_io_channel_set_flags (archive_command->ioc_out , G_IO_FLAG_NONBLOCK , NULL );
+		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(command);
+	return TRUE;
+}
 
+gboolean
+lsq_archive_command_stop(LSQArchiveCommand *archive_command)
+{
+	if(archive_command->child_pid != 0)
+		kill ( archive_command->child_pid , SIGHUP);
+	else
+		return FALSE; /* archive_command isn't running */
 	return TRUE;
 }
 
+void
+lsq_archive_command_child_watch_func(GPid pid, gint status, gpointer data)
+{
+	g_object_unref(G_OBJECT(data));
+}
+
 gboolean
-lsq_archive_command_stop(LSQArchiveCommand *command)
+lsq_archive_command_parse_stdout(GIOChannel *ioc, GIOCondition cond, gpointer data)
 {
+	GIOStatus status = G_IO_STATUS_NORMAL;
+	gint i = 0;
+	LSQArchiveCommand *archive_command = LSQ_ARCHIVE_COMMAND(data);
+
+	if(cond & (G_IO_PRI | G_IO_IN))
+	{
+		for(; i < 500; i++)
+		{
+			/* If parse_stdout returns FALSE, something seriously went wrong and we should cancel right away */
+			if(archive_command->parse_stdout(archive_command) == FALSE)
+			{
+				cond |= G_IO_ERR;
+			}
+		}
+	}
+	if(cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
+	{
+		g_io_channel_shutdown ( ioc,TRUE,NULL );
+		g_io_channel_unref (ioc);
+		g_object_unref(archive_command);
+		return FALSE; 
+	}
 	return TRUE;
 }

Modified: squeeze/trunk/libsqueeze/archive-command.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-command.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -47,7 +47,9 @@
 	GIOChannel *ioc_in;
 	GIOChannel *ioc_out;
 	GIOChannel *ioc_err;
-	gboolean    intrusive;
+	gboolean    safe;
+
+	gboolean  (*parse_stdout)(LSQArchiveCommand *archive_command);
 };
 
 typedef struct _LSQArchiveCommandClass LSQArchiveCommandClass;
@@ -57,23 +59,16 @@
 	GObjectClass parent;
 }; 
 
-/*
-GType               lsq_archive_command_get_type(void)                   G_GNUC_INTERNAL;
+GType               lsq_archive_command_get_type(void) G_GNUC_INTERNAL;
 LSQArchiveCommand  *lsq_archive_command_new(const gchar *comment, 
                                             LSQArchive *archive,
-                                            const gchar *command)        G_GNUC_INTERNAL;
+                                            const gchar *command,
+																						gboolean safe) G_GNUC_INTERNAL;
 
-void                lsq_archive_command_run(LSQArchiveCommand *command)  G_GNUC_INTERNAL;
-*/
-GType               lsq_archive_command_get_type(void);
-LSQArchiveCommand  *lsq_archive_command_new(const gchar *comment, 
-                                            LSQArchive *archive,
-                                            const gchar *command);
+gboolean            lsq_archive_command_run(LSQArchiveCommand *archive_command) G_GNUC_INTERNAL;
 
-gboolean            lsq_archive_command_run(LSQArchiveCommand *command);
+gboolean            lsq_archive_command_stop(LSQArchiveCommand *archive_command) G_GNUC_INTERNAL;
 
-gboolean            lsq_archive_command_stop(LSQArchiveCommand *command);
-
 G_END_DECLS
 
 #endif /* __LIBSQUEEZE_ARCHIVE_COMMAND_H__ */

Modified: squeeze/trunk/libsqueeze/archive-iter.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-iter.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-iter.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,5 +1,4 @@
-/*  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
+/*
  *  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/libsqueeze/archive-iter.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-iter.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-iter.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-compr.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-compr.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-compr.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-compr.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-compr.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-compr.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-gnu-tar.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-gnu-tar.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-gnu-tar.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-gnu-tar.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-gnu-tar.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-gnu-tar.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-rar.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-rar.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-rar.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-rar.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-rar.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-rar.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support-zip.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-zip.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-zip.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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
@@ -220,7 +218,7 @@
 		{
 			gchar *files = lsq_concat_filenames(filenames);
 
-			archive_command = lsq_archive_command_new("", archive, "zip -r %1$s %2$s");
+			archive_command = lsq_archive_command_new("", archive, "zip -r %1$s %2$s", FALSE);
 			g_object_set(archive_command, "files", files, NULL);
 			g_free(files);
 			g_object_unref(archive_command);
@@ -255,7 +253,7 @@
 
 			gchar *options = g_strconcat(" -d ", dest_path, NULL);
 
-			archive_command = lsq_archive_command_new("", archive, "zip -o %1$s %2$s %3$s");
+			archive_command = lsq_archive_command_new("", archive, "zip -o %1$s %2$s %3$s", TRUE);
 			g_object_set(archive_command, "files", files, NULL);
 			g_object_set(archive_command, "options", options, NULL);
 			g_object_unref(archive_command);
@@ -288,7 +286,7 @@
 		{
 			gchar *files = lsq_concat_filenames(filenames);
 
-			archive_command = lsq_archive_command_new("", archive, "zip -d %1$s %2$s");
+			archive_command = lsq_archive_command_new("", archive, "zip -d %1$s %2$s", FALSE);
 			g_object_set(archive_command, "files", files, NULL);
 			g_free(files);
 			g_object_unref(archive_command);
@@ -344,7 +342,7 @@
 			lsq_archive_set_entry_property_type(archive, i, G_TYPE_STRING, _("Checksum"));
 			i++;
 		}
-		archive_command = lsq_archive_command_new("", archive, "unzip -lv -qq %1$s");
+		archive_command = lsq_archive_command_new("", archive, "unzip -lv -qq %1$s", TRUE);
 	}
 	return 0;
 }

Modified: squeeze/trunk/libsqueeze/archive-support-zip.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-zip.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support-zip.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-support.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,4 +1,5 @@
-/*  This program is free software; you can redistribute it and/or modify
+/* 
+ *  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
  *  (at your option) any later version.

Modified: squeeze/trunk/libsqueeze/archive-support.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-support.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-support.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-tempfs.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-tempfs.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-tempfs.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/archive-tempfs.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-tempfs.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/archive-tempfs.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/internals.c
===================================================================
--- squeeze/trunk/libsqueeze/internals.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/internals.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,7 +1,4 @@
-
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/internals.h
===================================================================
--- squeeze/trunk/libsqueeze/internals.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/internals.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/libsqueeze.c
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/libsqueeze.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/libsqueeze.h
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/libsqueeze.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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/libsqueeze/slist.c
===================================================================
--- squeeze/trunk/libsqueeze/slist.c	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/slist.c	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,4 +1,18 @@
-
+/*
+ *  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
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
 #include <config.h>
 #include <string.h>
 #include <glib.h>

Modified: squeeze/trunk/libsqueeze/slist.h
===================================================================
--- squeeze/trunk/libsqueeze/slist.h	2007-02-11 22:39:44 UTC (rev 24949)
+++ squeeze/trunk/libsqueeze/slist.h	2007-02-12 00:01:46 UTC (rev 24950)
@@ -1,6 +1,4 @@
 /*
- *  Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
- *
  *  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



More information about the Xfce4-commits mailing list