]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix build and test failure without libbz2.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 16 Oct 2012 00:40:50 +0000 (09:40 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 16 Oct 2012 01:00:53 +0000 (10:00 +0900)
cpio/test/test_option_y.c
libarchive/archive_write_add_filter_bzip2.c
libarchive/test/test_empty_write.c

index 58734966ce6ab3ef0193e4f1dd73c3231a621a9d..54f270b81e0f7a2785a22f25a3517bdfcd654fb8 100644 (file)
@@ -40,9 +40,8 @@ DEFINE_TEST(test_option_y)
        p = slurpfile(&s, "archive.err");
        p[s] = '\0';
        if (r != 0) {
-               if (strstr(p, "compression not available") != NULL) {
-                       skipping("This version of bsdcpio was compiled "
-                           "without bzip2 support");
+               if (!canBzip2()) {
+                       skipping("bzip2 is not supported on this platform");
                        return;
                }
                failure("-y option is broken");
index e63c574ca60c0632ac65a795c1ed2c28a024b09f..88da803a395a9ec1688f1b75dbd0fdf52adfd2c2 100644 (file)
@@ -75,6 +75,49 @@ static int archive_compressor_bzip2_options(struct archive_write_filter *,
 static int archive_compressor_bzip2_write(struct archive_write_filter *,
                    const void *, size_t);
 
+/*
+ * Add a bzip2 compression filter to this write handle.
+ */
+int
+archive_write_add_filter_bzip2(struct archive *_a)
+{
+       struct archive_write *a = (struct archive_write *)_a;
+       struct archive_write_filter *f = __archive_write_allocate_filter(_a);
+       struct private_data *data;
+
+       archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
+           ARCHIVE_STATE_NEW, "archive_write_add_filter_bzip2");
+
+       data = calloc(1, sizeof(*data));
+       if (data == NULL) {
+               archive_set_error(&a->archive, ENOMEM, "Out of memory");
+               return (ARCHIVE_FATAL);
+       }
+       data->compression_level = 9; /* default */
+
+       f->data = data;
+       f->options = &archive_compressor_bzip2_options;
+       f->close = &archive_compressor_bzip2_close;
+       f->free = &archive_compressor_bzip2_free;
+       f->open = &archive_compressor_bzip2_open;
+       f->code = ARCHIVE_FILTER_BZIP2;
+       f->name = "bzip2";
+#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
+       return (ARCHIVE_OK);
+#else
+       data->pdata = __archive_write_program_allocate();
+       if (data->pdata == NULL) {
+               free(data);
+               archive_set_error(&a->archive, ENOMEM, "Out of memory");
+               return (ARCHIVE_FATAL);
+       }
+       data->compression_level = 0;
+       archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+           "Using external bzip2 program");
+       return (ARCHIVE_WARN);
+#endif
+}
+
 /*
  * Set write options.
  */
@@ -115,36 +158,6 @@ archive_compressor_bzip2_options(struct archive_write_filter *f,
 static int drive_compressor(struct archive_write_filter *,
                    struct private_data *, int finishing);
 
-/*
- * Add a bzip2 compression filter to this write handle.
- */
-int
-archive_write_add_filter_bzip2(struct archive *_a)
-{
-       struct archive_write *a = (struct archive_write *)_a;
-       struct archive_write_filter *f = __archive_write_allocate_filter(_a);
-       struct private_data *data;
-
-       archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
-           ARCHIVE_STATE_NEW, "archive_write_add_filter_bzip2");
-
-       data = calloc(1, sizeof(*data));
-       if (data == NULL) {
-               archive_set_error(&a->archive, ENOMEM, "Out of memory");
-               return (ARCHIVE_FATAL);
-       }
-       data->compression_level = 9; /* default */
-
-       f->data = data;
-       f->options = &archive_compressor_bzip2_options;
-       f->close = &archive_compressor_bzip2_close;
-       f->free = &archive_compressor_bzip2_free;
-       f->open = &archive_compressor_bzip2_open;
-       f->code = ARCHIVE_FILTER_BZIP2;
-       f->name = "bzip2";
-       return (ARCHIVE_OK);
-}
-
 /*
  * Setup callback.
  */
@@ -357,15 +370,11 @@ archive_compressor_bzip2_open(struct archive_write_filter *f)
                archive_strcat(&as, " -");
                archive_strappend_char(&as, '0' + data->compression_level);
        }
-       r = __archive_write_program_set_cmd(data->pdata, as.s);
-       archive_string_free(&as);
-       if (r != ARCHIVE_OK) {
-               archive_set_error(f->archive, ENOMEM, "Can't allocate memory");
-               return (ARCHIVE_FATAL);
-       }
        f->write = archive_compressor_bzip2_write;
 
-       return __archive_write_program_open(f, data->pdata);
+       r = __archive_write_program_open(f, data->pdata, as.s);
+       archive_string_free(&as);
+       return (r);
 }
 
 static int
@@ -385,4 +394,14 @@ archive_compressor_bzip2_close(struct archive_write_filter *f)
        return __archive_write_program_close(f, data->pdata);
 }
 
+static int
+archive_compressor_bzip2_free(struct archive_write_filter *f)
+{
+       struct private_data *data = (struct private_data *)f->data;
+
+       __archive_write_program_free(data->pdata);
+       free(data);
+       return (ARCHIVE_OK);
+}
+
 #endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
index c35979bfbf45bf65d5af954eb7ac0bbc75d59c5e..a983df503993b168224deedbd65ad599d22638a1 100644 (file)
@@ -78,7 +78,10 @@ DEFINE_TEST(test_empty_write)
        if (r != ARCHIVE_OK && !canBzip2()) {
                skipping("Empty write to bzip2-compressed archive");
        } else {
-               assertEqualIntA(a, ARCHIVE_OK, r);
+               if (r != ARCHIVE_OK && canBzip2())
+                       assertEqualIntA(a, ARCHIVE_WARN, r);
+               else
+                       assertEqualIntA(a, ARCHIVE_OK, r);
                assertEqualIntA(a, ARCHIVE_OK,
                    archive_write_open_memory(a, buff, sizeof(buff), &used));
                /* Write a file to it. */