WARNING : PEAR_PackageFileManager2 and PHP5 (realpath function)
| From: | Laurent Laville | Date: | Sun, 11 Nov 2007 10:39:40 +0000 |
| Subject: | WARNING : PEAR_PackageFileManager2 and PHP5 (realpath function) | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-48430@lists.php.net to get a copy of this message | ||
Hi all,
Few days ago, when I've released HTML_CSS 1.3.0, I've reused PFM2 with the script generator [1], and found a strange behaviour.
[1] http://cvs.php.net/viewvc.cgi/pear/HTML_CSS/package.php
My package.xml results gave me a <contents> structure with all directory names without first letter.
Example :
<contents>
<dir baseinstalldir="PHP" name="/">
<dir name="ompatInfo">
<file name="Cli.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
...
Rather than :
<contents>
<dir baseinstalldir="PHP" name="/">
<dir name="CompatInfo">
<file name="Cli.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
...
First, I though I did something wrong, and try to do it with new PEAR_PackageFileManager_Cli (package) that also gave me the wrong result.
As I did'nt have time to investigate until now, and I've let down the problem.
Now I realize that the problem came from PHP 5 itself and realpath() function.
I have not yet tested it under *Nix, but only on Windows platform (CLI or Apache module)
Realpath of a directory gave me a trailing "\" with PHP 5.2.4 and even now with PHP 5.2.5, but not with PHP 4.4.7
Probably generateContents() of PEAR_PackageFileManager2 need a fix !
Tell me if I should open a bug report or not ?
See test script below that demonstrate the bug
And outputs with PHP 4 and PHP 5
RealPath =c:\php\pear\PHP_CompatInfo
Dir name(c:/php/pear/PHP_CompatInfo/CompatInfo/pcicmd.php) =c:/php/pear/PHP_CompatInfo/CompatInfo
Path =CompatInfo
Results for PHP 4.4.7
RealPath =C:\php\pear\PHP_CompatInfo\
Dir name(C:/php/pear/PHP_CompatInfo/CompatInfo/pcicmd.php) =C:/php/pear/PHP_CompatInfo/CompatInfo
Path =ompatInfo
Results for PHP 5.2.4
Regards
Laurent
<?php
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cli') {
$eol = PHP_EOL;} else {
$eol = '<br/>' .PHP_EOL;} require_once 'PEAR/PackageFileManager2.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); $packagefile = 'c:/php/pear/PHP_CompatInfo/package2.xml'; $options = array('filelistgenerator' => 'cvs',
'packagefile' => 'package2.xml',
'baseinstalldir' => 'PHP',
'simpleoutput' => true,
'clearcontents' => true,
'changelogoldtonew' => false,
'ignore' => array('package.php', 'index.htm', 'package2.php',
'funclist.txt', 'updateVersionInfo.php', 'version.xml')
);
$p2 = &PEAR_PackageFileManager2::importOptions($packagefile, $options);
#$p2->generateContents();
$options = $p2->getOptions();
echo 'PFM2 options : ' . $eol; var_dump($options);
$generatorclass = 'PEAR_PackageFileManager_Cvs';
$generator = new $generatorclass($p2, $options);
$p2->clearContents($options['baseinstalldir']);
#$data = $generator->getFileList();
$package_directory = $options['packagedirectory'];
$data = $generator->dirList(substr($package_directory, 0, strlen($package_directory) - 1));
echo 'File List: ' . $eol;
$dl = var_dump($data);
echo 'RealPath ='. realpath($package_directory) . $eol;
foreach ($data as $file) {
$path = substr(dirname($file), strlen(str_replace(DIRECTORY_SEPARATOR,
'/',
realpath($package_directory))) + 1);
echo 'Dir name('.$file.') ='. dirname($file) . $eol;
echo 'Path ='. $path . $eol;
break; // first file example is enough to demonstrate differences
}
echo 'Results for PHP '. phpversion() . $eol;?>