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

Commit

Permalink
Merge branch 'hotfix/6077'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 14, 2014
2 parents 86a32e6 + 880e948 commit 1cd130f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
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 test/Storage/Adapter/FilesystemTest.php
Original file line number Diff line number Diff line change
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 1cd130f

Please sign in to comment.