Uploaded image for project: 'Log4php'
  1. Log4php
  2. LOG4PHP-86

LoggerAppenderRollingFileTest fails due to realpath()=>false on nonexisting files

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.0.0
    • Tests
    • None

    Description

      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

      Attachments

        Activity

          People

            lathspell Christian Brunotte
            lathspell Christian Brunotte
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: