Development

#43 (New cache machenism create sfCacheException on Windows environment)

You must first sign up to be able to contribute.

Ticket #43 (closed defect: fixed)

Opened 8 years ago

Last modified 7 years ago

New cache machenism create sfCacheException on Windows environment

Reported by: anonymous Assigned to:
Priority: major Milestone:
Component: Version:
Keywords: Cc:
Qualification:

Description

Part of the exception thrown on my system:

sfCacheException
message: 	Unable to write cache file "D:\sfProjectPath\cache\App1\dev\template\/localhost/App1/App1_dev.php/Navigation/leftMenuList\Tools_report.cache"
code: 	N/A
class: 	sfFileCache
file: 	D:\symfony-trunk\lib\symfony\cache\sfFileCache.class.php
line: 	519

Possible bug-code: (Revision 143)

class sfFileCache extends sfCache
{
  ...

  private function getFileName($id, $namespace)
  {
    $file = ($this->fileNameProtection) ? md5($id).$this->suffix : $id.$this->suffix;

    if ($namespace)
    {
'''      $path = $this->cacheDir.DIRECTORY_SEPARATOR.$namespace.DIRECTORY_SEPARATOR;
'''    }
    else
    {
      $path = $this->cacheDir.DIRECTORY_SEPARATOR;
    }
    if ($this->hashedDirectoryLevel > 0)
    {
      $hash = md5($file);
      for ($i = 0; $i < $this->hashedDirectoryLevel; $i++)
      {
        $path = $path.substr($hash, 0, $i + 1).'/';
      }
    }

    return array($path, $file);
  }
  
  ...
}

Reason: $namespace may contain '/' (using URI to create namespace) and DIRECTORY_SEPARATOR = '\' on Windows. In the end, error path is created: D:\sfProjectPath\cache\App1\dev\template\/localhost/App1/App1_dev.php/Navigation/leftMenuList\Tools_report.cache (Notice the \/ part)

Change History

11/18/05 12:46:43 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

fixed in r145.

12/01/05 09:46:40 changed by xiblack <xiblack@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.

This bug still occurs in sfViewCacheManage::remove() method. The possible buggy code is:

class sfViewCacheManager {
  ...

  public function generateNamespace($internalUri)
  {
    // generate uri
    $uri = $this->controller->genUrl(null, $internalUri);

    // add hostname to uri
    $request = $this->context->getRequest();
    $hostName = $request->getHost();
    $hostName = preg_replace('/[^a-z0-9]/i', '_', $hostName);
    $hostName = preg_replace('/_+/', '_', $hostName);
    $uri = '/'.$hostName.'/'.$uri;

    // replace multiple /
    $uri = preg_replace('#/+#', '/', $uri);

    return $uri;
  }

  ...
}

The above method generate the namespace based on internalURI, however, the namespace will be in this format: /host/path/to/app/module/action This will create error later in this code:

class sfFileCache {
  ...

  public function clean($namespace = null, $mode = 'all')
  {
    return $this->cleanDir($this->cacheDir.DIRECTORY_SEPARATOR.$namespace, $mode);
  }

  ...
}

The error path generated is something like this: D:\webs\mySfProj\cache\MyApp?\dev\template\/localhost/MyApp/MyApp_dev.php/Navigation/topMenuList

12/10/05 23:07:55 changed by fabien

  • status changed from reopened to closed.
  • resolution set to fixed.

fixed in r255