1
0
mirror of synced 2025-01-31 20:41:44 +03:00

Merge branch 'hotfix/#1072-fix-iteration-of-file-lock-region-on-no-match'

Close #1072
This commit is contained in:
Marco Pivetta 2015-01-15 00:55:16 +01:00
commit a88726d84e
3 changed files with 59 additions and 14 deletions

View File

@ -201,8 +201,14 @@ class FileLockRegion implements ConcurrentRegion
*/ */
public function evictAll() public function evictAll()
{ {
foreach (glob(sprintf("%s/*.%s" , $this->directory, self::LOCK_EXTENSION)) as $filename) { // The check below is necessary because on some platforms glob returns false
@unlink($filename); // when nothing matched (even though no errors occurred)
$filenames = glob(sprintf("%s/*.%s" , $this->directory, self::LOCK_EXTENSION));
if ($filenames) {
foreach ($filenames as $filename) {
@unlink($filename);
}
} }
return $this->region->evictAll(); return $this->region->evictAll();

View File

@ -27,17 +27,12 @@ class FileLockRegionTest extends AbstractRegionTest
*/ */
protected $directory; protected $directory;
/**
* {@inheritDoc}
*/
public function tearDown() public function tearDown()
{ {
if ( ! is_dir($this->directory)) { $this->cleanTestDirectory($this->directory);
return;
}
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->directory), RecursiveIteratorIterator::CHILD_FIRST) as $file) {
$file->isFile()
? @unlink($file->getRealPath())
: @rmdir($file->getRealPath());
}
} }
/** /**
@ -247,4 +242,46 @@ class FileLockRegionTest extends AbstractRegionTest
$this->assertNotNull($this->region->get($key)); $this->assertNotNull($this->region->get($key));
$this->assertFileNotExists($file); $this->assertFileNotExists($file);
} }
}
/**
* @group 1072
* @group DDC-3191
*/
public function testHandlesScanErrorsGracefullyOnEvictAll()
{
$region = $this->createRegion();
$reflectionDirectory = new \ReflectionProperty($region, 'directory');
$reflectionDirectory->setAccessible(true);
$reflectionDirectory->setValue($region, str_repeat('a', 10000));
set_error_handler(function () {}, E_WARNING);
$this->assertTrue($region->evictAll());
restore_error_handler();
}
/**
* @param string|null $path directory to clean
*/
private function cleanTestDirectory($path)
{
$path = $path ?: $this->directory;
if ( ! is_dir($path)) {
return;
}
$directoryIterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($directoryIterator as $file) {
if ($file->isFile()) {
@unlink($file->getRealPath());
} else {
@rmdir($file->getRealPath());
}
}
}
}

View File

@ -393,8 +393,10 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
return unlink($path); return unlink($path);
} else if (is_dir($path)) { } else if (is_dir($path)) {
$files = glob(rtrim($path,'/').'/*'); $files = glob(rtrim($path,'/').'/*');
foreach ($files as $file){ if (is_array($files)) {
$this->_deleteDirectory($file); foreach ($files as $file){
$this->_deleteDirectory($file);
}
} }
return rmdir($path); return rmdir($path);
} }