Skip to content

Commit d1a42dc

Browse files
committed
Support libarchive < 3.5.0
1 parent d62b611 commit d1a42dc

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

libarchive.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,13 @@ static void arch_obj_setup_support(arch_object *arch_obj)
285285
if (arch_obj->filters == NULL) {
286286
archive_read_support_filter_all(arch_obj->archive);
287287
} else {
288+
#if ARCHIVE_VERSION_NUMBER >= 3005000
288289
for (uint32_t i = 0; i < arch_obj->filters_count; i++) {
289290
archive_read_support_filter_by_code(arch_obj->archive, arch_obj->filters[i]);
290291
}
292+
#else
293+
archive_read_support_filter_all(arch_obj->archive);
294+
#endif
291295
}
292296
if (arch_obj->formats == NULL) {
293297
archive_read_support_format_all(arch_obj->archive);
@@ -454,6 +458,11 @@ PHP_METHOD(libarchive_Archive, supportFilters)
454458
"Cannot change filter after archive has been opened", -1);
455459
return;
456460
}
461+
#if ARCHIVE_VERSION_NUMBER < 3005000
462+
php_error_docref(NULL, E_WARNING,
463+
"supportFilters() requires libarchive >= 3.5.0; all filters will be enabled");
464+
RETURN_THIS();
465+
#endif
457466
efree(arch_obj->filters);
458467
arch_obj->filters = safe_emalloc(num_args, sizeof(int), 0);
459468
arch_obj->filters_count = num_args;

libarchive.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace libarchive {
66

7+
/** @var int
8+
* @cvalue ARCHIVE_VERSION_NUMBER */ const LIBARCHIVE_VERSION_ID = UNKNOWN;
9+
710
/** @var int
811
* @cvalue ARCHIVE_FILTER_NONE */ const FILTER_NONE = UNKNOWN;
912
/** @var int

libarchive_arginfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static const zend_function_entry class_libarchive_Archive_methods[] = {
7373

7474
static void register_libarchive_symbols(int module_number)
7575
{
76+
REGISTER_LONG_CONSTANT("libarchive\\LIBARCHIVE_VERSION_ID", ARCHIVE_VERSION_NUMBER, CONST_PERSISTENT);
7677
REGISTER_LONG_CONSTANT("libarchive\\FILTER_NONE", ARCHIVE_FILTER_NONE, CONST_PERSISTENT);
7778
REGISTER_LONG_CONSTANT("libarchive\\FILTER_GZIP", ARCHIVE_FILTER_GZIP, CONST_PERSISTENT);
7879
REGISTER_LONG_CONSTANT("libarchive\\FILTER_BZIP2", ARCHIVE_FILTER_BZIP2, CONST_PERSISTENT);

tests/support-formats-filters.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
--TEST--
22
supportFormats() and supportFilters() restrict archive format and filter detection
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('archive')) die('skip archive extension not loaded');
6+
if (\libarchive\LIBARCHIVE_VERSION_ID < 3005000) die('skip requires libarchive >= 3.5.0');
7+
?>
38
--FILE--
49
<?php
510

0 commit comments

Comments
 (0)