Skip to content

Commit ac9a265

Browse files
committed
- bump zip extension version to 1.16.0 - add ZipArchive::setMtimeName and ZipArchive::setMtimeIndex methods
1 parent 3bae179 commit ac9a265

File tree

7 files changed

+170
-1
lines changed

7 files changed

+170
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ PHP NEWS
118118

119119
- Zip:
120120
. Fixed bug #72374 (remove_path strips first char of filename). (tyage)
121+
. Add ZipArchive::setMtimeName and ZipArchive::setMtimeIndex methods
121122

122123
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

ext/zip/config.m4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ if test "$PHP_ZIP" != "no"; then
99
PHP_EVAL_INCLINE($LIBZIP_CFLAGS)
1010
PHP_EVAL_LIBLINE($LIBZIP_LIBS, ZIP_SHARED_LIBADD)
1111

12+
PHP_CHECK_LIBRARY(zip, zip_file_set_mtime,
13+
[
14+
AC_DEFINE(HAVE_SET_MTIME, 1, [Libzip >= 1.0.0 with zip_file_set_mtime])
15+
], [
16+
AC_MSG_WARN(Libzip >= 1.0.0 needed for setting mtime)
17+
], [
18+
-L$LIBZIP_LIBDIR
19+
])
20+
1221
PHP_CHECK_LIBRARY(zip, zip_file_set_encryption,
1322
[
1423
AC_DEFINE(HAVE_ENCRYPTION, 1, [Libzip >= 1.2.0 with encryption support])

ext/zip/php_zip.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,67 @@ static ZIPARCHIVE_METHOD(setCompressionIndex)
23012301
}
23022302
/* }}} */
23032303

2304+
#ifdef HAVE_SET_MTIME
2305+
/* {{{ proto bool ZipArchive::setMtimeName(string name, int timestamp[, int flags])
2306+
Set the modification time of a file in zip, using its name */
2307+
static ZIPARCHIVE_METHOD(setMtimeName)
2308+
{
2309+
struct zip *intern;
2310+
zval *this = ZEND_THIS;
2311+
size_t name_len;
2312+
char *name;
2313+
zip_int64_t idx;
2314+
zend_long mtime, flags = 0;
2315+
2316+
ZIP_FROM_OBJECT(intern, this);
2317+
2318+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l",
2319+
&name, &name_len, &mtime, &flags) == FAILURE) {
2320+
return;
2321+
}
2322+
2323+
if (name_len < 1) {
2324+
php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
2325+
}
2326+
2327+
idx = zip_name_locate(intern, name, 0);
2328+
if (idx < 0) {
2329+
RETURN_FALSE;
2330+
}
2331+
2332+
if (zip_file_set_mtime(intern, (zip_uint64_t)idx,
2333+
(time_t)mtime, (zip_uint32_t)flags) != 0) {
2334+
RETURN_FALSE;
2335+
}
2336+
RETURN_TRUE;
2337+
}
2338+
/* }}} */
2339+
2340+
/* {{{ proto bool ZipArchive::setMtimeIndex(int index, int timestamp[, int flags])
2341+
Set the modification time of a file in zip, using its index */
2342+
static ZIPARCHIVE_METHOD(setMtimeIndex)
2343+
{
2344+
struct zip *intern;
2345+
zval *this = ZEND_THIS;
2346+
zend_long index;
2347+
zend_long mtime, flags = 0;
2348+
2349+
ZIP_FROM_OBJECT(intern, this);
2350+
2351+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l",
2352+
&index, &mtime, &flags) == FAILURE) {
2353+
return;
2354+
}
2355+
2356+
if (zip_file_set_mtime(intern, (zip_uint64_t)index,
2357+
(time_t)mtime, (zip_uint32_t)flags) != 0) {
2358+
RETURN_FALSE;
2359+
}
2360+
RETURN_TRUE;
2361+
}
2362+
/* }}} */
2363+
#endif
2364+
23042365
/* {{{ proto bool ZipArchive::deleteIndex(int index)
23052366
Delete a file using its index */
23062367
static ZIPARCHIVE_METHOD(deleteIndex)
@@ -2755,6 +2816,10 @@ static const zend_function_entry zip_class_functions[] = {
27552816
#endif
27562817
ZIPARCHIVE_ME(setCompressionName, arginfo_class_ZipArchive_setCompressionName, ZEND_ACC_PUBLIC)
27572818
ZIPARCHIVE_ME(setCompressionIndex, arginfo_class_ZipArchive_setCompressionIndex, ZEND_ACC_PUBLIC)
2819+
#ifdef HAVE_SET_MTIME
2820+
ZIPARCHIVE_ME(setMtimeName, arginfo_class_ZipArchive_setMtimeName, ZEND_ACC_PUBLIC)
2821+
ZIPARCHIVE_ME(setMtimeIndex, arginfo_class_ZipArchive_setMtimeIndex, ZEND_ACC_PUBLIC)
2822+
#endif
27582823
#ifdef HAVE_ENCRYPTION
27592824
ZIPARCHIVE_ME(setEncryptionName, arginfo_class_ZipArchive_setEncryptionName, ZEND_ACC_PUBLIC)
27602825
ZIPARCHIVE_ME(setEncryptionIndex, arginfo_class_ZipArchive_setEncryptionIndex, ZEND_ACC_PUBLIC)

ext/zip/php_zip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern zend_module_entry zip_module_entry;
3131
#define ZIP_OVERWRITE ZIP_TRUNCATE
3232
#endif
3333

34-
#define PHP_ZIP_VERSION "1.15.6"
34+
#define PHP_ZIP_VERSION "1.16.0"
3535

3636
#define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
3737

ext/zip/php_zip.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public function setCommentIndex(int $index, string $comment) {}
9090
/** @return null|false */
9191
public function setCommentName(string $name, string $comment) {}
9292

93+
/** @return null|false */
94+
public function setMtimeIndex(int $index, int $timestamp, int $flags = 0) {}
95+
96+
/** @return null|false */
97+
public function setMtimeName(string $name, int $timestamp, int $flags = 0) {}
98+
9399
/** @return string|false */
94100
public function getCommentIndex(int $index, int $flags = 0) {}
95101

ext/zip/php_zip_arginfo.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setCommentName, 0, 0, 2)
111111
ZEND_ARG_TYPE_INFO(0, comment, IS_STRING, 0)
112112
ZEND_END_ARG_INFO()
113113

114+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setMtimeIndex, 0, 0, 2)
115+
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
116+
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
117+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
118+
ZEND_END_ARG_INFO()
119+
120+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setMtimeName, 0, 0, 2)
121+
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
122+
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
123+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
124+
ZEND_END_ARG_INFO()
125+
114126
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_getCommentIndex, 0, 0, 1)
115127
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
116128
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)

ext/zip/tests/oo_setmtime.phpt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
--TEST--
2+
setMtime
3+
--SKIPIF--
4+
<?php
5+
/* $Id$ */
6+
if(!extension_loaded('zip')) die('skip');
7+
if (!method_exists('ZipArchive', 'setMtimeName')) die('skip libzip too old');
8+
?>
9+
--INI--
10+
date.timezone=UTC
11+
--FILE--
12+
<?php
13+
$dirname = dirname(__FILE__) . '/';
14+
include $dirname . 'utils.inc';
15+
$file = $dirname . '__tmp_oo_set_mtime.zip';
16+
17+
@unlink($file);
18+
19+
$zip = new ZipArchive;
20+
if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
21+
exit('failed');
22+
}
23+
24+
$zip->addFromString('foo', 'entry #1');
25+
$zip->addFromString('bar', 'entry #2');
26+
27+
$t1 = mktime(0,0,0,12,25,2019);
28+
$t2 = mktime(0,0,0,14,7,2018);
29+
30+
echo "Set 1\n";
31+
$s = $zip->statName('foo');
32+
var_dump($s['mtime'] > $t1);
33+
var_dump($zip->setMtimeName('foo', $t1));
34+
$s = $zip->statName('foo');
35+
// ONLY with 1.6.0 - var_dump($s['mtime'] == $t1);
36+
37+
echo "Set 2\n";
38+
$s = $zip->statIndex(1);
39+
var_dump($s['mtime'] > $t2);
40+
var_dump($zip->setMtimeIndex(1, $t2));
41+
$s = $zip->statIndex(1);
42+
// ONLY with 1.6.0 - var_dump($s['mtime'] == $t2);
43+
44+
if (!$zip->status == ZIPARCHIVE::ER_OK) {
45+
echo "failed to write zip\n";
46+
}
47+
$zip->close();
48+
49+
if (!$zip->open($file)) {
50+
@unlink($file);
51+
exit('failed');
52+
}
53+
54+
echo "Get 1\n";
55+
$s = $zip->statIndex(0);
56+
var_dump($s['mtime'] == $t1);
57+
58+
echo "Get 2\n";
59+
$s = $zip->statName('bar');
60+
var_dump($s['mtime'] == $t2);
61+
62+
$zip->close();
63+
@unlink($file);
64+
65+
?>
66+
--EXPECTF--
67+
Set 1
68+
bool(true)
69+
bool(true)
70+
Set 2
71+
bool(true)
72+
bool(true)
73+
Get 1
74+
bool(true)
75+
Get 2
76+
bool(true)

0 commit comments

Comments
 (0)