Merge branch '2.3' into 2.7

* 2.3:
  [Filesystem] Fix false positive in ->remove()
  [Validator] Fix the locale validator so it treats a locale alias as a valid locale

Conflicts:
	src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
	src/Symfony/Component/Validator/Constraints/LocaleValidator.php
	src/Symfony/Component/Validator/composer.json
This commit is contained in:
Nicolas Grekas 2016-03-08 14:51:36 +01:00
commit a1c95f79d6
6 changed files with 21 additions and 19 deletions

View File

@ -158,12 +158,13 @@ class Filesystem
$files = iterator_to_array($this->toIterator($files));
$files = array_reverse($files);
foreach ($files as $file) {
if (@(unlink($file) || rmdir($file))) {
continue;
}
if (is_link($file)) {
// Workaround https://bugs.php.net/52176
if (!@unlink($file) && !@rmdir($file)) {
$error = error_get_last();
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
}
// See https://bugs.php.net/52176
$error = error_get_last();
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
} elseif (is_dir($file)) {
$this->remove(new \FilesystemIterator($file));
@ -171,11 +172,9 @@ class Filesystem
$error = error_get_last();
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
}
} elseif ($this->exists($file)) {
if (!@unlink($file)) {
$error = error_get_last();
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
}
} elseif (file_exists($file)) {
$error = error_get_last();
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
}
}
}
@ -435,7 +434,7 @@ class Filesystem
$target = str_replace($originDir, $targetDir, $file->getPathname());
if ($copyOnWindows) {
if (is_link($file) || is_file($file)) {
if (is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} elseif (is_dir($file)) {
$this->mkdir($target);

View File

@ -744,6 +744,8 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($link);
$this->assertTrue(!is_link($link));
$this->assertTrue(!is_file($link));
$this->assertTrue(!is_dir($link));
}
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
@ -917,7 +919,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->mirror($sourcePath, $targetPath);
$this->assertTrue(is_dir($targetPath));
$this->assertFileEquals($sourcePath.'file1', $targetPath.DIRECTORY_SEPARATOR.'link1');
$this->assertFileEquals($sourcePath.'file1', $targetPath.'link1');
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
}
@ -937,7 +939,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->mirror($sourcePath, $targetPath);
$this->assertTrue(is_dir($targetPath));
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt');
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
}
@ -961,7 +963,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->mirror($sourcePath, $targetPath);
$this->assertTrue(is_dir($targetPath));
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt');
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
$this->assertEquals('\\' === DIRECTORY_SEPARATOR ? realpath($sourcePath.'\nested') : 'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
}

View File

@ -36,9 +36,8 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR && null === self::$symlinkOnWindows) {
$target = tempnam(sys_get_temp_dir(), 'sl');
$link = sys_get_temp_dir().'/sl'.microtime(true).mt_rand();
if (self::$symlinkOnWindows = @symlink($target, $link)) {
unlink($link);
}
self::$symlinkOnWindows = @symlink($target, $link) && is_link($link);
@unlink($link);
unlink($target);
}
}

View File

@ -43,8 +43,9 @@ class LocaleValidator extends ConstraintValidator
$value = (string) $value;
$locales = Intl::getLocaleBundle()->getLocaleNames();
$aliases = Intl::getLocaleBundle()->getAliases();
if (!isset($locales[$value])) {
if (!isset($locales[$value]) && !in_array($value, $aliases)) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))

View File

@ -67,6 +67,7 @@ class LocaleValidatorTest extends AbstractConstraintValidatorTest
array('pt'),
array('pt_PT'),
array('zh_Hans'),
array('fil_PH'),
);
}

View File

@ -22,7 +22,7 @@
"require-dev": {
"doctrine/common": "~2.3",
"symfony/http-foundation": "~2.1",
"symfony/intl": "~2.4",
"symfony/intl": "~2.7.4",
"symfony/yaml": "~2.0,>=2.0.5",
"symfony/config": "~2.2",
"symfony/property-access": "~2.3",