[file-roller] use a custom rpm2cpio to support different types of rpm payloads
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [file-roller] use a custom rpm2cpio to support different types of rpm payloads
- Date: Fri, 31 Jul 2009 13:51:51 +0000 (UTC)
commit 570c30b09a1c7417e893a0f34ba522195f4d9975
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Jul 31 15:47:22 2009 +0200
use a custom rpm2cpio to support different types of rpm payloads
[fixes bug #590262]
[fixes bug #574005]
configure.ac | 1 +
src/Makefile.am | 6 ++-
src/commands/Makefile.am | 7 +++
src/commands/rpm2cpio.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++
src/fr-archive.c | 3 +
src/fr-command-rpm.c | 8 ++--
src/sh/Makefile.am | 2 +-
7 files changed, 154 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 38242df..e2d8d35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,6 +150,7 @@ AC_CONFIG_FILES([Makefile
data/icons/scalable/apps/Makefile
copy-n-paste/Makefile
src/Makefile
+ src/commands/Makefile
src/sh/Makefile
nautilus/Makefile
help/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 6bcd6ee..e871437 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = sh
+SUBDIRS = commands sh
bin_PROGRAMS = file-roller
@@ -16,8 +16,10 @@ endif
if RUN_IN_PLACE
uidir = $(top_srcdir)/data/ui
+privexecdir = $(abs_top_builddir)/src/commands/
else
uidir = $(datadir)/file-roller/ui
+privexecdir = $(libexecdir)/file-roller/
endif
INCLUDES = \
@@ -32,7 +34,7 @@ INCLUDES = \
-DPKG_DATA_DIR=\"$(pkgdatadir)\" \
-DPIXMAPSDIR=\""$(datadir)/pixmaps"\" \
-DGLADEDIR=\""$(gladedir)"\" \
- -DPRIVEXECDIR=\""$(libexecdir)/file-roller/"\" \
+ -DPRIVEXECDIR=\"$(privexecdir)\" \
$(DISABLE_DEPRECATED) \
$(FR_CFLAGS)
diff --git a/src/commands/Makefile.am b/src/commands/Makefile.am
new file mode 100644
index 0000000..b51c338
--- /dev/null
+++ b/src/commands/Makefile.am
@@ -0,0 +1,7 @@
+privexecdir = $(libexecdir)/$(PACKAGE)
+privexec_PROGRAMS = rpm2cpio
+
+INCLUDES = $(DISABLE_DEPRECATED) $(FR_CFLAGS)
+
+rpm2cpio_SOURCES = rpm2cpio.c
+rpm2cpio_LDADD = $(FR_LIBS)
diff --git a/src/commands/rpm2cpio.c b/src/commands/rpm2cpio.c
new file mode 100644
index 0000000..034cd89
--- /dev/null
+++ b/src/commands/rpm2cpio.c
@@ -0,0 +1,134 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * File-Roller
+ *
+ * Copyright (C) 2001 The Free Software Foundation, Inc.
+ *
+ * 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 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 Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+
+
+static const char *
+get_mime_type_from_magic_numbers (char *buffer)
+{
+ static struct {
+ const char *mime_type;
+ const char *first_bytes;
+ int offset;
+ int len;
+ } sniffer_data [] = {
+ { "application/x-bzip2", "BZh", 0, 3 },
+ { "application/x-gzip", "\037\213", 0, 2 },
+ { "application/x-xz", "\3757zXZ\000", 0, 6 },
+ { NULL, NULL, 0 }
+ };
+ int i;
+
+ for (i = 0; sniffer_data[i].mime_type != NULL; i++)
+ if (memcmp (sniffer_data[i].first_bytes,
+ buffer + sniffer_data[i].offset,
+ sniffer_data[i].len) == 0)
+ {
+ return sniffer_data[i].mime_type;
+ }
+
+ return NULL;
+}
+
+
+int
+main (int argc, char **argv)
+{
+ const char *filename;
+ GString *cpio_args;
+ int i;
+ FILE *stream;
+ guchar bytes[8];
+ int il, dl, sigsize, offset;
+ const char *mime_type;
+ const char *archive_command;
+ char *command;
+
+ if (argc < 3)
+ return 0;
+
+ filename = argv[1];
+ cpio_args = g_string_new (argv[2]);
+ for (i = 3; i < argc; i++) {
+ g_string_append (cpio_args, " ");
+ g_string_append (cpio_args, argv[i]);
+ }
+
+ stream = fopen (filename, "r");
+ if (stream == NULL)
+ return 1;
+
+ if (fseek (stream, 104 , SEEK_CUR) != 0) {
+ fclose (stream);
+ return 1;
+ }
+ if (fread (bytes, 1, 8, stream) == 0) {
+ fclose (stream);
+ return 1;
+ }
+ il = 256 * (256 * (256 * bytes[0] + bytes[1]) + bytes[2]) + bytes[3];
+ dl = 256 * (256 * (256 * bytes[4] + bytes[5]) + bytes[6]) + bytes[7];
+ sigsize = 8 + 16 * il + dl;
+ offset = 104 + sigsize + (8 - (sigsize % 8)) % 8 + 8;
+ if (fseek (stream, offset, SEEK_SET) != 0) {
+ fclose (stream);
+ return 1;
+ }
+ if (fread (bytes, 1, 8, stream) == 0) {
+ fclose (stream);
+ return 1;
+ }
+ il = 256 * (256 * (256 * bytes[0] + bytes[1]) + bytes[2]) + bytes[3];
+ dl = 256 * (256 * (256 * bytes[4] + bytes[5]) + bytes[6]) + bytes[7];
+ sigsize = 8 + 16 * il + dl;
+ offset = offset + sigsize;
+
+ /* get the payload type */
+
+ if (fseek (stream, offset, SEEK_SET) != 0) {
+ fclose (stream);
+ return 1;
+ }
+ if (fread (bytes, 1, 8, stream) == 0) {
+ fclose (stream);
+ return 1;
+ }
+ mime_type = get_mime_type_from_magic_numbers ((char *)bytes);
+ if (mime_type == NULL)
+ archive_command = "lzma -dc";
+ else if (strcmp (mime_type, "application/x-xz") == 0)
+ archive_command = "xz -dc";
+ else if (strcmp (mime_type, "application/x-gzip") == 0)
+ archive_command = "gzip -dc";
+ else
+ archive_command = "bzip2 -dc";
+ fclose (stream);
+
+ command = g_strdup_printf ("sh -c \"dd if=%s ibs=%u skip=1 2>/dev/null | %s | cpio %s\"", g_shell_quote (filename), offset, archive_command, cpio_args->str);
+
+ return system (command);
+}
diff --git a/src/fr-archive.c b/src/fr-archive.c
index 74d09ce..79ea86b 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -442,10 +442,13 @@ get_mime_type_from_magic_numbers (GFile *file)
{ "application/x-7z-compressed", "7z\274\257\047\034", 0, 5 },
{ "application/x-ace", "**ACE**", 7, 7 },
{ "application/x-arj", "\x60\xea", 0, 2 },
+ { "application/x-bzip2", "BZh", 0, 3 },
{ "application/x-gzip", "\037\213", 0, 2 },
{ "application/x-lzip", "LZIP", 0, 4 },
+ { "application/x-lzop", "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 0, 9 },
{ "application/x-rar", "Rar!", 0, 4 },
{ "application/x-rzip", "RZIP", 0, 4 },
+ { "application/x-xz", "\3757zXZ\000", 0, 6 },
{ "application/x-zoo", "\xdc\xa7\xc4\xfd", 20, 4 },
{ "application/zip", "PK\003\004", 0, 4 },
{ "application/zip", "PK00PK\003\004", 0, 8 },
diff --git a/src/fr-command-rpm.c b/src/fr-command-rpm.c
index 01b3475..152d618 100644
--- a/src/fr-command-rpm.c
+++ b/src/fr-command-rpm.c
@@ -175,7 +175,7 @@ fr_command_rpm_list (FrCommand *comm)
fr_process_begin_command (comm->process, "sh");
fr_process_add_arg (comm->process, "-c");
- fr_process_add_arg_concat (comm->process, "rpm2cpio ", comm->e_filename, " | cpio -itv", NULL);
+ fr_process_add_arg_concat (comm->process, PRIVEXECDIR "rpm2cpio ", comm->e_filename, " -itv", NULL);
fr_process_end_command (comm->process);
fr_process_start (comm->process);
}
@@ -198,9 +198,9 @@ fr_command_rpm_extract (FrCommand *comm,
fr_process_set_working_dir (comm->process, dest_dir);
fr_process_add_arg (comm->process, "-c");
- cmd = g_string_new ("rpm2cpio ");
+ cmd = g_string_new (PRIVEXECDIR "rpm2cpio ");
g_string_append (cmd, comm->e_filename);
- g_string_append (cmd, " | cpio -idu ");
+ g_string_append (cmd, " -idu ");
for (scan = file_list; scan; scan = scan->next) {
char *filename = g_shell_quote (scan->data);
g_string_append (cmd, filename);
@@ -232,7 +232,7 @@ fr_command_rpm_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("rpm2cpio"))
+ if (is_program_in_path ("cpio"))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/sh/Makefile.am b/src/sh/Makefile.am
index 324222f..25f0f89 100644
--- a/src/sh/Makefile.am
+++ b/src/sh/Makefile.am
@@ -1,4 +1,4 @@
-shdir = $(libexecdir)/file-roller
+shdir = $(libexecdir)/$(PACKAGE)
sh_DATA = isoinfo.sh
EXTRA_DIST = $(sh_DATA)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]