Author: stephan
Date: 2007-02-21 16:14:15 +0000 (Wed, 21 Feb 2007)
New Revision: 25005

Modified:
   squeeze/trunk/libsqueeze/archive-support-zip.c
   squeeze/trunk/tests/zip/test-extract.c
   squeeze/trunk/tests/zip/test-zip-add.pl
   squeeze/trunk/tests/zip/test-zip-extract.pl
Log:
Fix extract for zip
Changed test-suites (actually testing something)



Modified: squeeze/trunk/libsqueeze/archive-support-zip.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-zip.c      2007-02-21 15:05:21 UTC 
(rev 25004)
+++ squeeze/trunk/libsqueeze/archive-support-zip.c      2007-02-21 16:14:15 UTC 
(rev 25005)
@@ -217,9 +217,11 @@
                   !g_strcasecmp((gchar 
*)thunar_vfs_mime_info_get_name(archive->mime_info), "application/zip"))
                {
                        gchar *files = lsq_concat_filenames(filenames);
+                       gchar *options = g_strdup("");
 
-                       archive_command = lsq_archive_command_new("", archive, 
"zip -r %1$s %2$s", FALSE);
+                       archive_command = lsq_archive_command_new("", archive, 
"zip %3$s -r %1$s %2$s", FALSE);
                        g_object_set_data(G_OBJECT(archive_command), "files", 
g_strdup(files));
+                       g_object_set_data(G_OBJECT(archive_command), "options", 
options);
                        g_free(files);
                        lsq_archive_command_run(archive_command);
                        g_object_unref(archive_command);
@@ -254,9 +256,9 @@
 
                        gchar *options = g_strconcat(" -d ", dest_path, NULL);
 
-                       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);
+                       archive_command = lsq_archive_command_new("", archive, 
"unzip -o %1$s %2$s %3$s", TRUE);
+                       g_object_set_data(G_OBJECT(archive_command), "files", 
files);
+                       g_object_set_data(G_OBJECT(archive_command), "options", 
options);
                        lsq_archive_command_run(archive_command);
                        g_object_unref(archive_command);
                        g_free(dest_path);
@@ -289,7 +291,7 @@
                        gchar *files = lsq_concat_filenames(filenames);
 
                        archive_command = lsq_archive_command_new("", archive, 
"zip -d %1$s %2$s", FALSE);
-                       g_object_set(archive_command, "files", files, NULL);
+                       g_object_set_data(G_OBJECT(archive_command), "files", 
files);
                        lsq_archive_command_run(archive_command);
                        g_object_unref(archive_command);
                        g_free(files);

Modified: squeeze/trunk/tests/zip/test-extract.c
===================================================================
--- squeeze/trunk/tests/zip/test-extract.c      2007-02-21 15:05:21 UTC (rev 
25004)
+++ squeeze/trunk/tests/zip/test-extract.c      2007-02-21 16:14:15 UTC (rev 
25005)
@@ -20,26 +20,81 @@
 #include <thunar-vfs/thunar-vfs.h>
 #include <libsqueeze/libsqueeze.h>
 
-int main()
+GMainLoop *loop = NULL;
+gint ret_val = 0;
+gchar *filename = NULL;
+gchar *dest_path = NULL;
+
+static GOptionEntry entries[] =
 {
-       g_type_init();
+       {       "extract", 'e', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, 
&filename,
+               NULL,
+               NULL
+       },
+       {       "destination", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, 
&dest_path,
+               NULL,
+               NULL
+       },
+       { NULL }
+};
 
-       LSQArchive *archive = NULL;
-       gchar *current_dir = g_get_current_dir();
-       gchar *path = g_strconcat(current_dir, "/data/test.zip", NULL);
+void
+cb_command_terminated(LSQArchive *archive, GError *error)
+{
+       if(loop)
+               g_main_loop_quit(loop);
+       else
+               ret_val = 1;
+       if(error)
+       {
+               g_debug("%s", error->message);
+               ret_val = 1;
+       }
+}
 
+int main(int argc, char **argv)
+{
+       g_type_init();
        thunar_vfs_init();
        lsq_init();
 
-       lsq_new_archive(path, TRUE, "application/zip", &archive);
+       LSQArchive *archive = NULL;
+       LSQArchiveSupport *archive_support = NULL;
+       GSList *files = NULL;
+       gint i = 0;
 
+       GOptionContext *opt_context = g_option_context_new("test-add -n 
<archive> [filename ...]");
+       g_option_context_add_main_entries(opt_context, entries, NULL);
+       g_option_context_parse (opt_context, &argc, &argv, NULL);
 
+       if(filename == NULL)
+       {
+               g_print("Filename is not specified\n");
+               return 1;
+       }
+
+       lsq_open_archive(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);
+
+       for(i = 1; i < argc; i++)
+       {
+               files = g_slist_prepend(files, argv[i]);
+       }
+
+       if(lsq_archive_support_extract(archive_support, archive, dest_path, 
files))
+               ret_val = 1;
+
+       if(ret_val == 0)
+       {
+               loop = g_main_loop_new(NULL, FALSE);
+               g_main_loop_run(loop);
+       }
+
        lsq_close_archive(archive);
 
        lsq_shutdown();
        thunar_vfs_shutdown();
-
-       g_free(path);
-       g_free(current_dir);
-       return 0;
+       return ret_val;
 }

Modified: squeeze/trunk/tests/zip/test-zip-add.pl
===================================================================
--- squeeze/trunk/tests/zip/test-zip-add.pl     2007-02-21 15:05:21 UTC (rev 
25004)
+++ squeeze/trunk/tests/zip/test-zip-add.pl     2007-02-21 16:14:15 UTC (rev 
25005)
@@ -1,23 +1,21 @@
 #!/usr/bin/env perl
 chomp($cwd = `pwd`);
-$test_file = "$cwd/data/test.zip";
+$test_archive = "$cwd/data/test-extract.zip";
 
 print "========================================";
 print "========================================\n";
 print "Target archive:\n";
-print "$test_file\n";
+print "$test_archive\n";
 
[EMAIL PROTECTED] = ("./test-add", "-n", $test_file, "$cwd/data/1.txt");
-system(@args) == 0
-       or die "system @args failed: $?";
-
-unlink $test_file;
-
[EMAIL PROTECTED] = ("./test-add", "-n", $test_file, "$cwd/data/2.txt");
[EMAIL PROTECTED] = ("./test-add", "-n", $test_archive, "$cwd/data/2.txt");
 system(@args) != 0
        or die "system @args should fail: $?";
 
 unlink $test_file;
 
[EMAIL PROTECTED] = ("./test-add", "-n", $test_archive, "$cwd/data/1.txt");
+system(@args) == 0
+       or die "system @args failed: $?";
+
 print "========================================";
 print "========================================\n";

Modified: squeeze/trunk/tests/zip/test-zip-extract.pl
===================================================================
--- squeeze/trunk/tests/zip/test-zip-extract.pl 2007-02-21 15:05:21 UTC (rev 
25004)
+++ squeeze/trunk/tests/zip/test-zip-extract.pl 2007-02-21 16:14:15 UTC (rev 
25005)
@@ -1,2 +1,21 @@
 #!/usr/bin/env perl
-exit 1;
+chomp($cwd = `pwd`);
+$test_archive = "$cwd/data/test-extract.zip";
+
+print "========================================";
+print "========================================\n";
+print "Target archive:\n";
+print "$test_archive\n";
+
+unlink "$cwd/data/extract/1.txt";
+
[EMAIL PROTECTED] = ("./test-extract", "-d", "$cwd/data/extract", "-e", 
$test_archive);
+system(@args) == 0
+       or die "system @args failed: $?";
+
+#die "A" unless -e "$cwd/data/extract/1.txt";
+
+unlink $test_archive;
+
+print "========================================";
+print "========================================\n";

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to