[gnome-autoar] Workaround for archive_write_set_format



commit 96a61c72ffcf2a51f0ce7805523c05f06dc6d8a2
Author: Ting-Wei Lan <lantw44 gmail com>
Date:   Fri Sep 6 21:38:01 2013 +0800

    Workaround for archive_write_set_format
    
    archive_write_set_format does not recognize all available format codes, so
    we have to manually maps format codes to functions. This problem is found in
    libarchive 3.1.2 source code, libarchive/archive_write_set_format.c.

 gnome-autoar/autoar-create.c        |   25 ++++++-
 gnome-autoar/autoar-format-filter.c |  140 +++++++++++++++++++++++++++++------
 gnome-autoar/autoar-format-filter.h |   12 +++-
 3 files changed, 150 insertions(+), 27 deletions(-)
---
diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c
index 30cf04a..4b35b09 100644
--- a/gnome-autoar/autoar-create.c
+++ b/gnome-autoar/autoar-create.c
@@ -1211,8 +1211,11 @@ autoar_create_step_initialize_object (AutoarCreate *arcreate)
 
   AutoarFormat format;
   AutoarFilter filter;
+  AutoarFormatFunc format_func;
+  AutoarFilterFunc filter_func;
 
   AutoarCreatePrivate *priv;
+  int r;
 
   priv = arcreate->priv;
 
@@ -1232,9 +1235,25 @@ autoar_create_step_initialize_object (AutoarCreate *arcreate)
 
   priv->extension = autoar_format_filter_get_extension (format, filter);
 
-  archive_write_set_bytes_in_last_block (priv->a, 1);
-  archive_write_add_filter (priv->a, autoar_filter_get_filter_libarchive (filter));
-  archive_write_set_format (priv->a, autoar_format_get_format_libarchive (format));
+  r = archive_write_set_bytes_in_last_block (priv->a, 1);
+  if (r != ARCHIVE_OK) {
+    priv->error = autoar_common_g_error_new_a (priv->a, NULL);
+    return;
+  }
+
+  format_func = autoar_format_get_libarchive_write (format);
+  r = (*format_func)(priv->a);
+  if (r != ARCHIVE_OK) {
+    priv->error = autoar_common_g_error_new_a (priv->a, NULL);
+    return;
+  }
+
+  filter_func = autoar_filter_get_libarchive_write (filter);
+  r = (*filter_func)(priv->a);
+  if (r != ARCHIVE_OK) {
+    priv->error = autoar_common_g_error_new_a (priv->a, NULL);
+    return;
+  }
 }
 
 static void
diff --git a/gnome-autoar/autoar-format-filter.c b/gnome-autoar/autoar-format-filter.c
index 97e0233..90d0ea6 100644
--- a/gnome-autoar/autoar-format-filter.c
+++ b/gnome-autoar/autoar-format-filter.c
@@ -42,6 +42,8 @@ struct _AutoarFormatDescription
   char *keyword;
   char *mime_type;
   char *description;
+  AutoarFormatFunc libarchive_read;
+  AutoarFormatFunc libarchive_write;
 };
 
 struct _AutoarFilterDescription
@@ -52,56 +54,122 @@ struct _AutoarFilterDescription
   char *keyword;
   char *mime_type;
   char *description;
+  AutoarFilterFunc libarchive_read;
+  AutoarFilterFunc libarchive_write;
 };
 
 static AutoarFormatDescription autoar_format_description[] = {
   { AUTOAR_FORMAT_ZIP,       ARCHIVE_FORMAT_ZIP,                 "zip",  "zip",
-    "application/zip",       "Zip archive" },
+    "application/zip",       "Zip archive",
+    archive_read_support_format_zip,
+    archive_write_set_format_zip },
+
   { AUTOAR_FORMAT_TAR,       ARCHIVE_FORMAT_TAR_PAX_RESTRICTED,  "tar",  "tar",
-    "application/x-tar",     "Tar archive (restricted pax)" },
+    "application/x-tar",     "Tar archive (restricted pax)",
+    archive_read_support_format_tar,
+    archive_write_set_format_pax_restricted },
+
   { AUTOAR_FORMAT_CPIO,      ARCHIVE_FORMAT_CPIO_POSIX,          "cpio", "cpio",
-    "application/x-cpio",    "CPIO archive" },
+    "application/x-cpio",    "CPIO archive",
+    archive_read_support_format_cpio,
+    archive_write_set_format_cpio },
+
   { AUTOAR_FORMAT_7ZIP,      ARCHIVE_FORMAT_7ZIP,                "7z",   "7z-compressed",
-    "application/x-7z-compressed", "7-zip archive" },
+    "application/x-7z-compressed", "7-zip archive",
+    archive_read_support_format_7zip,
+    archive_write_set_format_7zip },
+
   { AUTOAR_FORMAT_AR_BSD,    ARCHIVE_FORMAT_AR_BSD,              "a",    "ar",
-    "application/x-ar",      "AR archive (BSD)" },
+    "application/x-ar",      "AR archive (BSD)",
+    archive_read_support_format_ar,
+    archive_write_set_format_ar_bsd },
+
   { AUTOAR_FORMAT_AR_SVR4,   ARCHIVE_FORMAT_AR_GNU,              "a",    "ar",
-    "application/x-ar",      "AR archive (SVR4)" },
+    "application/x-ar",      "AR archive (SVR4)",
+    archive_read_support_format_ar,
+    archive_write_set_format_ar_svr4 },
+
   { AUTOAR_FORMAT_CPIO_NEWC, ARCHIVE_FORMAT_CPIO_SVR4_NOCRC,     "cpio", "sv4cpio",
-    "application/x-sv4cpio", "SV4 CPIO archive" },
+    "application/x-sv4cpio", "SV4 CPIO archive",
+    archive_read_support_format_cpio,
+    archive_write_set_format_cpio_newc },
+
   { AUTOAR_FORMAT_GNUTAR,    ARCHIVE_FORMAT_TAR_GNUTAR,          "tar",  "tar",
-    "application/x-tar",     "Tar archive (GNU tar)" },
+    "application/x-tar",     "Tar archive (GNU tar)",
+    archive_read_support_format_gnutar,
+    archive_write_set_format_gnutar },
+
   { AUTOAR_FORMAT_ISO9660,   ARCHIVE_FORMAT_ISO9660,             "iso",  "cd-image",
-    "application/x-cd-image", "Raw CD Image" },
+    "application/x-cd-image", "Raw CD Image",
+    archive_read_support_format_iso9660,
+    archive_write_set_format_iso9660 },
+
   { AUTOAR_FORMAT_PAX,       ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, "tar",  "tar",
-    "application/x-tar",     "Tar archive (pax)" },
+    "application/x-tar",     "Tar archive (pax)",
+    archive_read_support_format_tar,
+    archive_write_set_format_pax },
+
   { AUTOAR_FORMAT_USTAR,     ARCHIVE_FORMAT_TAR_USTAR,           "tar",  "tar",
-    "application/x-tar",     "Tar archive (ustar)" },
+    "application/x-tar",     "Tar archive (ustar)",
+    archive_read_support_format_tar,
+    archive_write_set_format_ustar },
+
   { AUTOAR_FORMAT_XAR,       ARCHIVE_FORMAT_XAR,                 "xar",  "xar",
-    "application/x-xar",     "Xar archive" }
+    "application/x-xar",     "Xar archive",
+    archive_read_support_format_xar,
+    archive_write_set_format_xar }
 };
 
 static AutoarFilterDescription autoar_filter_description[] = {
   { AUTOAR_FILTER_NONE,      ARCHIVE_FILTER_NONE,                "",     "",
-    "",                      "None" },
+    "",                      "None",
+    archive_read_support_filter_none,
+    archive_write_add_filter_none },
+
   { AUTOAR_FILTER_COMPRESS,  ARCHIVE_FILTER_COMPRESS,            "Z",    "compress",
-    "application/x-compress", "UNIX-compressed" },
+    "application/x-compress", "UNIX-compressed",
+    archive_read_support_filter_compress,
+    archive_write_add_filter_compress },
+
   { AUTOAR_FILTER_GZIP,      ARCHIVE_FILTER_GZIP,                "gz",   "gzip",
-    "application/gzip",      "Gzip" },
+    "application/gzip",      "Gzip",
+    archive_read_support_filter_gzip,
+    archive_write_add_filter_gzip },
+
   { AUTOAR_FILTER_BZIP2,     ARCHIVE_FILTER_BZIP2,               "bz2",  "bzip",
-    "application/x-bzip",    "Bzip2" },
+    "application/x-bzip",    "Bzip2",
+    archive_read_support_filter_bzip2,
+    archive_write_add_filter_bzip2 },
+
   { AUTOAR_FILTER_XZ,        ARCHIVE_FILTER_XZ,                  "xz",   "xz",
-    "application/x-xz",      "XZ" },
+    "application/x-xz",      "XZ",
+    archive_read_support_filter_xz,
+    archive_write_add_filter_xz },
+
   { AUTOAR_FILTER_LZMA,      ARCHIVE_FILTER_LZMA,                "lzma", "lzma",
-    "application/x-lzma",    "LZMA" },
+    "application/x-lzma",    "LZMA",
+    archive_read_support_filter_lzma,
+    archive_write_add_filter_lzma },
+
   { AUTOAR_FILTER_LZIP,      ARCHIVE_FILTER_LZIP,                "lz",   "lzip",
-    "application/x-lzip",    "Lzip" },
+    "application/x-lzip",    "Lzip",
+    archive_read_support_filter_lzip,
+    archive_write_add_filter_lzip },
+
   { AUTOAR_FILTER_LZOP,      ARCHIVE_FILTER_LZOP,                "lzo",  "lzop",
-    "application/x-lzop",    "LZO" },
+    "application/x-lzop",    "LZO",
+    archive_read_support_filter_lzop,
+    archive_write_add_filter_lzop },
+
   { AUTOAR_FILTER_GRZIP,     ARCHIVE_FILTER_GRZIP,               "grz",  "grzip",
-    "application/x-grzip",   "GRZip" },
+    "application/x-grzip",   "GRZip",
+    archive_read_support_filter_grzip,
+    archive_write_add_filter_grzip },
+
   { AUTOAR_FILTER_LRZIP,     ARCHIVE_FILTER_LRZIP,               "lrz",  "lrzip",
-    "application/x-lrzip",   "Long Range ZIP (lrzip)" }
+    "application/x-lrzip",   "Long Range ZIP (lrzip)",
+    archive_read_support_filter_lrzip,
+    archive_write_add_filter_lrzip }
 };
 
 AutoarFormat
@@ -160,6 +228,20 @@ autoar_format_get_description_libarchive (AutoarFormat format)
   return str;
 }
 
+AutoarFormatFunc
+autoar_format_get_libarchive_read (AutoarFormat format)
+{
+  g_return_val_if_fail (autoar_format_is_valid (format), NULL);
+  return autoar_format_description[format - 1].libarchive_read;
+}
+
+AutoarFormatFunc
+autoar_format_get_libarchive_write (AutoarFormat format)
+{
+  g_return_val_if_fail (autoar_format_is_valid (format), NULL);
+  return autoar_format_description[format - 1].libarchive_write;
+}
+
 AutoarFilter
 autoar_filter_last (void)
 {
@@ -216,6 +298,20 @@ autoar_filter_get_description_libarchive (AutoarFilter filter)
   return str;
 }
 
+AutoarFilterFunc
+autoar_filter_get_libarchive_read (AutoarFilter filter)
+{
+  g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
+  return autoar_filter_description[filter - 1].libarchive_read;
+}
+
+AutoarFilterFunc
+autoar_filter_get_libarchive_write (AutoarFilter filter)
+{
+  g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
+  return autoar_filter_description[filter - 1].libarchive_write;
+}
+
 gchar*
 autoar_format_filter_get_mime_type (AutoarFormat format,
                                     AutoarFilter filter)
diff --git a/gnome-autoar/autoar-format-filter.h b/gnome-autoar/autoar-format-filter.h
index 2175936..d01d8c7 100644
--- a/gnome-autoar/autoar-format-filter.h
+++ b/gnome-autoar/autoar-format-filter.h
@@ -26,6 +26,7 @@
 #ifndef AUTOAR_FORMAT_H
 #define AUTOAR_FORMAT_H
 
+#include <archive.h>
 #include <glib.h>
 
 G_BEGIN_DECLS
@@ -62,21 +63,28 @@ typedef enum {
   AUTOAR_FILTER_LAST /*< skip >*/
 } AutoarFilter;
 
+typedef int (*AutoarFormatFunc) (struct archive*);
+typedef int (*AutoarFilterFunc) (struct archive*);
+
 AutoarFormat  autoar_format_last                        (void);
 gboolean      autoar_format_is_valid                    (AutoarFormat format);
 const char   *autoar_format_get_mime_type               (AutoarFormat format);
 const char   *autoar_format_get_extension               (AutoarFormat format);
 const char   *autoar_format_get_description             (AutoarFormat format);
-int           autoar_format_get_format_libarchive       (AutoarFormat format);
 gchar        *autoar_format_get_description_libarchive  (AutoarFormat format);
+int           autoar_format_get_format_libarchive       (AutoarFormat format);
+AutoarFormatFunc autoar_format_get_libarchive_read      (AutoarFormat format);
+AutoarFormatFunc autoar_format_get_libarchive_write     (AutoarFormat format);
 
 AutoarFilter  autoar_filter_last                        (void);
 gboolean      autoar_filter_is_valid                    (AutoarFilter filter);
 const char   *autoar_filter_get_mime_type               (AutoarFilter filter);
 const char   *autoar_filter_get_extension               (AutoarFilter filter);
 const char   *autoar_filter_get_description             (AutoarFilter filter);
-int           autoar_filter_get_filter_libarchive       (AutoarFilter filter);
 gchar        *autoar_filter_get_description_libarchive  (AutoarFilter filter);
+int           autoar_filter_get_filter_libarchive       (AutoarFilter filter);
+AutoarFilterFunc autoar_filter_get_libarchive_read      (AutoarFilter filter);
+AutoarFilterFunc autoar_filter_get_libarchive_write     (AutoarFilter filter);
 
 gchar        *autoar_format_filter_get_mime_type        (AutoarFormat format,
                                                          AutoarFilter filter);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]