From 9b50cf342db1b0557a513f00b48b0a805b4d262f Mon Sep 17 00:00:00 2001 From: Mikko Koppanen Date: Mon, 16 Mar 2009 10:16:16 +0000 Subject: [PATCH] Closes bug #47667 --- ext/zip/lib/zip_open.c | 5 ++++- ext/zip/tests/bug47667.phpt | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ext/zip/tests/bug47667.phpt diff --git a/ext/zip/lib/zip_open.c b/ext/zip/lib/zip_open.c index 65f982543c..4b219556c8 100644 --- a/ext/zip/lib/zip_open.c +++ b/ext/zip/lib/zip_open.c @@ -65,8 +65,11 @@ zip_open(const char *fn, int flags, int *zep) struct zip_cdir *cdir; int i; off_t len; - + if (flags & ZIP_OVERWRITE) { + return _zip_allocate_new(fn, zep); + } + switch (_zip_file_exists(fn, flags, zep)) { case -1: if (!(flags & ZIP_OVERWRITE)) { diff --git a/ext/zip/tests/bug47667.phpt b/ext/zip/tests/bug47667.phpt new file mode 100644 index 0000000000..960a3c5d7e --- /dev/null +++ b/ext/zip/tests/bug47667.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #47667 (ZipArchive::OVERWRITE seems to have no effect) +--SKIPIF-- + +--FILE-- +open($filename, ZipArchive::CREATE) !== true) { + exit("Unable to open the zip file"); +} else { + $zip->addFromString('foo.txt', 'foo bar foobar'); + $zip->close(); +} + +for ($i = 0; $i < 10; $i++) { + $zip = new ZipArchive(); + if ($zip->open($filename, ZipArchive::OVERWRITE) !== true) { + exit("Unable to open the zip file"); + } + $zip->addFromString("foo_{$i}.txt", 'foo bar foobar'); + $zip->close(); +} + +$zip = new ZipArchive(); +if ($zip->open($filename, ZipArchive::CREATE) !== true) { + exit("Unable to open the zip file"); +} + +echo "files: " , $zip->numFiles; + +unlink($filename); + +--EXPECT-- +files: 1 -- 2.50.1