From: Nikita Popov Date: Sun, 28 Jan 2018 20:53:38 +0000 (+0100) Subject: Merge branch 'PHP-7.2' X-Git-Tag: php-7.3.0alpha1~529 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d79a0bf7487ebadb57a3813654327fa4f901829b;p=php Merge branch 'PHP-7.2' --- d79a0bf7487ebadb57a3813654327fa4f901829b diff --cc ext/phar/phar_object.c index 47f5737243,5a85bf7ad9..7bba619574 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@@ -4346,6 -4346,35 +4346,35 @@@ static int phar_extract_file(zend_bool } /* }}} */ + static int extract_helper(phar_archive_data *archive, zend_string *search, char *pathto, size_t pathto_len, zend_bool overwrite, char **error) { /* {{{ */ + int extracted = 0; + phar_entry_info *entry; + + if (!search) { + /* nothing to match -- extract all files */ + ZEND_HASH_FOREACH_PTR(&archive->manifest, entry) { - if (FAILURE == phar_extract_file(overwrite, entry, pathto, (int)pathto_len, error)) return -1; ++ if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; + extracted++; + } ZEND_HASH_FOREACH_END(); + } else if ('/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) { + /* ends in "/" -- extract all entries having that prefix */ + ZEND_HASH_FOREACH_PTR(&archive->manifest, entry) { + if (0 != strncmp(ZSTR_VAL(search), entry->filename, ZSTR_LEN(search))) continue; - if (FAILURE == phar_extract_file(overwrite, entry, pathto, (int)pathto_len, error)) return -1; ++ if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; + extracted++; + } ZEND_HASH_FOREACH_END(); + } else { + /* otherwise, looking for an exact match */ + entry = zend_hash_find_ptr(&archive->manifest, search); + if (NULL == entry) return 0; - if (FAILURE == phar_extract_file(overwrite, entry, pathto, (int)pathto_len, error)) return -1; ++ if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; + return 1; + } + + return extracted; + } + /* }}} */ + /* {{{ proto bool Phar::extractTo(string pathto[[, mixed files], bool overwrite]) * Extract one or more file from a phar archive, optionally overwriting existing files */