From 2277396fe368ce13d4a31eb820db2554392cf6a4 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Mon, 14 Apr 2008 15:21:41 +0000 Subject: [PATCH] fix edge case where a new phar is created via mkdir(), add to dir.phpt test --- ext/phar/phar.c | 4 ++-- ext/phar/tests/dir.phpt | 4 +++- ext/phar/util.c | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 85f62b8e176..8760e5dbbda 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2045,7 +2045,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, offset += 4 + entry->filename_len + sizeof(entry_buffer) + entry->metadata_str.len + (entry->is_dir ? 1 : 0); /* compress and rehash as necessary */ - if (oldfile && !entry->is_modified) { + if ((oldfile && !entry->is_modified) || entry->is_dir) { continue; } if (!phar_get_efp(entry TSRMLS_CC)) { @@ -2302,7 +2302,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, if (zend_hash_get_current_data(&phar->manifest, (void **)&entry) == FAILURE) { continue; } - if (entry->is_deleted) { + if (entry->is_deleted || entry->is_dir) { continue; } if (entry->cfp) { diff --git a/ext/phar/tests/dir.phpt b/ext/phar/tests/dir.phpt index 233e28c6820..2aa8880e3ea 100644 --- a/ext/phar/tests/dir.phpt +++ b/ext/phar/tests/dir.phpt @@ -31,11 +31,13 @@ var_dump(file_exists($pname3 . '/another/dir/')); ini_set('phar.readonly', 1); mkdir($pname . '/fails'); ini_set('phar.readonly', 0); -mkdir('phar://oops.phar/fails'); +// create new phar by mkdir +mkdir('phar://' . dirname(__FILE__) . '/ok.phar/fails'); ?> ===DONE=== --CLEAN-- + --EXPECTF-- diff --git a/ext/phar/util.c b/ext/phar/util.c index 0791bb0ebbc..f07000df876 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -471,6 +471,7 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char if (entry->is_dir) { *ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data)); (*ret)->position = 0; + (*ret)->fp = NULL; (*ret)->phar = phar; (*ret)->for_write = for_write; (*ret)->internal_file = entry;