From: Greg Beaver Date: Thu, 24 Apr 2008 04:14:05 +0000 (+0000) Subject: remove redundant unreachable code in Phar::copy, augment test, and add failing condit... X-Git-Tag: RELEASE_2_0_0b1~234 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f0c9caac5cc2e9ed63f4f05b5183a870a7b1fde;p=php remove redundant unreachable code in Phar::copy, augment test, and add failing condition that needs to be fixed --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 7cc2f2423f..6ce425e104 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -2806,16 +2806,16 @@ PHP_METHOD(Phar, copy) RETURN_FALSE; } - if (!zend_hash_exists(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len)) { + if (!zend_hash_exists(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len) || SUCCESS != zend_hash_find(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len, (void**)&oldentry) || oldentry->is_deleted) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "file \"%s\" does not exist in phar %s", oldfile, phar_obj->arc.archive->fname); + "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->arc.archive->fname); RETURN_FALSE; } if (zend_hash_exists(&phar_obj->arc.archive->manifest, newfile, (uint) newfile_len)) { if (SUCCESS == zend_hash_find(&phar_obj->arc.archive->manifest, newfile, (uint) newfile_len, (void**)&temp) || !temp->is_deleted) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "file \"%s\" cannot be copied to file \"%s\", file must not already exist %s", oldfile, newfile, phar_obj->arc.archive->fname); + "file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->arc.archive->fname); RETURN_FALSE; } } @@ -2826,12 +2826,6 @@ PHP_METHOD(Phar, copy) RETURN_FALSE; } - if (!zend_hash_exists(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len) || SUCCESS != zend_hash_find(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len, (void**)&oldentry) || oldentry->is_deleted) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->arc.archive->fname); - RETURN_FALSE; - } - memcpy((void *) &newentry, oldentry, sizeof(phar_entry_info)); if (newentry.metadata) { zval *t; diff --git a/ext/phar/tests/phar_copy.phpt b/ext/phar/tests/phar_copy.phpt index 74a342dbb2..0a43947bd1 100644 --- a/ext/phar/tests/phar_copy.phpt +++ b/ext/phar/tests/phar_copy.phpt @@ -42,7 +42,21 @@ $p2 = new Phar($fname2); echo "\n"; echo 'a: ' , file_get_contents($p2['a']->getPathName()); echo 'b: ' ,file_get_contents($p2['b']->getPathName()); -echo 'c: ' ,file_get_contents($p2['c']->getPathName()), $p2['c']->getMetaData(); +echo 'c: ' ,file_get_contents($p2['c']->getPathName()), $p2['c']->getMetaData(), "\n"; +ini_set('phar.readonly', 0); +try { +$p2->copy('notexisting', 'another'); +} catch (Exception $e) { +echo $e->getMessage() . "\n"; +} +try { +$p2->copy('a', 'b'); +} catch (Exception $e) { +echo $e->getMessage() . "\n"; +} +$p2['a']->compress(Phar::GZ); +$p2->copy('a', 'd'); +echo $p2['d']->getContent() . "\n"; ?> ===DONE=== --CLEAN-- @@ -51,4 +65,8 @@ echo 'c: ' ,file_get_contents($p2['c']->getPathName()), $p2['c']->getMetaData(); --EXPECTF-- hihifile "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s -a: hib: hic: hia===DONE=== \ No newline at end of file +a: hib: hic: hia +file "notexisting" cannot be copied to file "another", file does not exist in %sphar_copy2.phar.php +file "a" cannot be copied to file "b", file must not already exist in phar %sphar_copy2.phar.php +hi +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/phar_oo_compressallgz.phpt b/ext/phar/tests/phar_oo_compressallgz.phpt index 7204daf54d..55e7435f95 100644 --- a/ext/phar/tests/phar_oo_compressallgz.phpt +++ b/ext/phar/tests/phar_oo_compressallgz.phpt @@ -39,7 +39,11 @@ var_dump($phar['b']->isCompressed(Phar::BZ2)); var_dump(file_get_contents($pname . '/c')); var_dump($phar['c']->isCompressed(Phar::GZ)); var_dump($phar['b']->isCompressed(Phar::BZ2)); - +try { +$phar->compressFiles(25); +} catch (Exception $e) { +echo $e->getMessage() . "\n"; +} ?> ===DONE=== --CLEAN-- @@ -63,4 +67,5 @@ bool(false) string(1) "c" bool(true) bool(false) +Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2 ===DONE===