]> granicus.if.org Git - php/commitdiff
remove redundant unreachable code in Phar::copy, augment test, and add failing condit...
authorGreg Beaver <cellog@php.net>
Thu, 24 Apr 2008 04:14:05 +0000 (04:14 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 24 Apr 2008 04:14:05 +0000 (04:14 +0000)
ext/phar/phar_object.c
ext/phar/tests/phar_copy.phpt
ext/phar/tests/phar_oo_compressallgz.phpt

index 7cc2f2423f527487d07a85b5050125e1ffcbf329..6ce425e1044446831da3a6871368ed25bfc124bf 100755 (executable)
@@ -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;
index 74a342dbb2a598a1e04a48f12e935fbe17f6d3ea..0a43947bd1472118b503bcdbfb80d4193b2c4a94 100644 (file)
@@ -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
index 7204daf54d3915477f60bcbe631acf4862441c12..55e7435f95171b7a67be5a89062dad3972309583 100644 (file)
@@ -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===