Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/6077' into develop
Browse files Browse the repository at this point in the history
Forward port #6077
  • Loading branch information
weierophinney committed Apr 14, 2014
2 parents ce50ec6 + 6a7a2ff commit fe5a9e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Cache/Storage/Adapter/Filesystem.php
Expand Up @@ -198,7 +198,7 @@ public function clearByNamespace($namespace)
$flags = GlobIterator::SKIP_DOTS | GlobIterator::CURRENT_AS_PATHNAME;
$path = $options->getCacheDir()
. str_repeat(DIRECTORY_SEPARATOR . $prefix . '*', $options->getDirLevel())
. DIRECTORY_SEPARATOR . $prefix . '*';
. DIRECTORY_SEPARATOR . $prefix . '*.*';
$glob = new GlobIterator($path, $flags);

ErrorHandler::start();
Expand Down Expand Up @@ -236,7 +236,7 @@ public function clearByPrefix($prefix)
$flags = GlobIterator::SKIP_DOTS | GlobIterator::CURRENT_AS_PATHNAME;
$path = $options->getCacheDir()
. str_repeat(DIRECTORY_SEPARATOR . $nsPrefix . '*', $options->getDirLevel())
. DIRECTORY_SEPARATOR . $nsPrefix . $prefix . '*';
. DIRECTORY_SEPARATOR . $nsPrefix . $prefix . '*.*';
$glob = new GlobIterator($path, $flags);

ErrorHandler::start();
Expand Down
23 changes: 23 additions & 0 deletions tests/ZendTest/Cache/Storage/Adapter/FilesystemTest.php
Expand Up @@ -301,4 +301,27 @@ public function testClearExpiredExceptionTriggersEvent()
$this->_storage->clearExpired();
chmod($dirs[0], 0700); //set dir back to writable for tearDown
}

public function testClearByNamespaceWithUnexpectedDirectory()
{
// create cache items at 2 different directory levels
$this->_storage->getOptions()->setDirLevel(2);
$this->_storage->setItem('a_key', 'a_value');
$this->_storage->getOptions()->setDirLevel(1);
$this->_storage->setItem('b_key', 'b_value');
$this->_storage->clearByNamespace($this->_storage->getOptions()->getNamespace());
}

public function testClearByPrefixWithUnexpectedDirectory()
{
// create cache items at 2 different directory levels
$this->_storage->getOptions()->setDirLevel(2);
$this->_storage->setItem('a_key', 'a_value');
$this->_storage->getOptions()->setDirLevel(1);
$this->_storage->setItem('b_key', 'b_value');
$glob = glob($this->_tmpCacheDir.'/*');
//contrived prefix which will collide with an existing directory
$prefix = substr(md5('a_key'), 2, 2);
$this->_storage->clearByPrefix($prefix);
}
}

0 comments on commit fe5a9e7

Please sign in to comment.