]> granicus.if.org Git - php/commitdiff
rename Phar::getRunningPhar\(\) to Phar::running\(\) and by default return the full
authorGreg Beaver <cellog@php.net>
Sun, 23 Mar 2008 06:00:31 +0000 (06:00 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 23 Mar 2008 06:00:31 +0000 (06:00 +0000)
phar url, if optional parameter is false, return the path to the phar on disk.  Fix a double free on failed mount

ext/phar/phar_object.c
ext/phar/tests/mounteddir.phpt

index 38ea938c84a4dcb3067b9cb8f7b2bcde6b76ffaa..a29c3ae4e272567082198df057b0da62c57c6656 100755 (executable)
@@ -425,22 +425,33 @@ static void phar_postprocess_ru_web(char *fname, int fname_len, char **entry, in
 }
 /* }}} */
 
-/* {{{ proto void Phar::getRunningPhar()
- * return the name of the currently running phar archive
+/* {{{ proto void Phar::running([bool retphar = true])
+ * return the name of the currently running phar archive.  If the optional parameter
+ * is set to true, return the phar:// URL to the currently running phar
  */
-PHP_METHOD(Phar, getRunningPhar)
+PHP_METHOD(Phar, running)
 {
        char *fname, *arch, *entry;
        int fname_len, arch_len, entry_len;
+       zend_bool retphar = 1;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &retphar) == FAILURE) {
+               return;
+       }
 
        fname = zend_get_executed_filename(TSRMLS_C);
        fname_len = strlen(fname);
 
        if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len TSRMLS_CC)) {
                efree(entry);
-               RETURN_STRINGL(arch, arch_len, 0);
+               if (retphar) {
+                       RETVAL_STRINGL(fname, arch_len + 7, 1);
+                       efree(arch);
+                       return;
+               } else {
+                       RETURN_STRINGL(arch, arch_len, 0);
+               }
        }
-       efree(entry);
        RETURN_STRING("", 0);
 }
 /* }}} */
@@ -474,7 +485,6 @@ PHP_METHOD(Phar, mount)
 carry_on:
                if (SUCCESS != phar_mount_entry(*pphar, actual, actual_len, path, path_len TSRMLS_CC)) {
                        zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Mounting of %s to %s within phar %s failed", path, actual, arch);
-                       efree(arch);
                }
                efree(arch);
                return;
@@ -3565,6 +3575,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setStub, 0, 0, 1)
        ZEND_ARG_INFO(0, maxlen)
 ZEND_END_ARG_INFO();
 
+static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_running, 0, 0, 1)
+       ZEND_ARG_INFO(0, retphar)
+ZEND_END_ARG_INFO();
+
 #endif /* HAVE_SPL */
 
 zend_function_entry php_archive_methods[] = {
@@ -3619,7 +3634,7 @@ zend_function_entry php_archive_methods[] = {
        PHP_ME(Phar, isValidPharFilename,   NULL,                      ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
        PHP_ME(Phar, loadPhar,              arginfo_phar_loadPhar,     ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
        PHP_ME(Phar, mapPhar,               arginfo_phar_mapPhar,      ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
-       PHP_ME(Phar, getRunningPhar,        NULL,                      ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
+       PHP_ME(Phar, running,               arginfo_phar_running,      ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
        PHP_ME(Phar, mount,                 arginfo_phar_mount,        ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
        PHP_ME(Phar, mungServer,            arginfo_phar_mungServer,   ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
        PHP_ME(Phar, webPhar,               arginfo_phar_webPhar,      ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
index 876d6c3478a9d0f8d95c78314da19efc46e40601..e09705bab163b7d14807edde2af402b6724e7c38 100644 (file)
@@ -9,7 +9,7 @@ phar.readonly=0
 $fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
 $a = new Phar($fname);
 $a['index.php'] = '<?php
-Phar::mount("testit", dirname(Phar::getRunningPhar()) . "/testit");
+Phar::mount("testit", dirname(Phar::running(0)) . "/testit");
 include "testit/extfile.php";
 include "testit/extfile2.php";
 ?>';