You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by "Christian Hammers (JIRA)" <ji...@apache.org> on 2009/10/11 01:38:32 UTC
[jira] Updated: (LOG4PHP-86) LoggerAppenderRollingFileTest fails
due to realpath()=>false on nonexisting files
[ https://issues.apache.org/jira/browse/LOG4PHP-86?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Christian Hammers updated LOG4PHP-86:
-------------------------------------
Fix Version/s: 2.0
> LoggerAppenderRollingFileTest fails due to realpath()=>false on nonexisting files
> ---------------------------------------------------------------------------------
>
> Key: LOG4PHP-86
> URL: https://issues.apache.org/jira/browse/LOG4PHP-86
> Project: Log4php
> Issue Type: Bug
> Components: Tests
> Reporter: Christian Hammers
> Fix For: 2.0
>
>
> The Unit-Tests failed for me and I figured out that it was caused by realpath() which returns false if the file does not already exist.
> That was until PHP-5.3 not true for BSD, btw., which may also explain why it was no issue on MacOS computers...
> --- src/main/php/appenders/LoggerAppenderRollingFile.php (Revision 814880)
> +++ src/main/php/appenders/LoggerAppenderRollingFile.php (Arbeitskopie)
> @@ -130,7 +143,11 @@
> public function setFileName($fileName) {
> $this->fileName = $fileName;
> - $this->expandedFileName = realpath($fileName);
> + // As LoggerAppenderFile does not create the directory, it has to exist.
> + // realpath() fails if the argument does not exist so the filename is separated.
> + $this->expandedFileName = realpath(dirname($fileName));
> + if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!");
> + $this->expandedFileName .= '/'.basename($fileName);
> }
> I added the following test to src/test/php/appenders/LoggerAppenderRollingFileTest.php
> + public function testSetFileName() {
> + $appender = new LoggerAppenderRollingFile("mylogger");
> + $appender->setFileName('target/temp/../././temp/phpunit/doesnotexist.log');
> + $expandedFileName = self::readAttribute($appender, 'expandedFileName');
> + self::assertEquals(1, preg_match('/\/target\/temp\/phpunit\/doesnotexist.log$/', $expandedFileName));
> + }
> expandedFileName is private and has no getter thus the ugly readAttribute()
> bye,
> -christian-
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.