Merge branch '2.7' into 2.8

* 2.7:
  [Filesystem] Fix false positive in ->remove()
  [Filesystem] Cleanup/sync with 2.3
  [Validator] Fix the locale validator so it treats a locale alias as a valid locale
  reference form type by name on Symfony 2.7
This commit is contained in:
Fabien Potencier 2016-03-08 18:53:24 +01:00
commit fe6d904a3d
5 changed files with 31 additions and 32 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

@ -347,7 +347,7 @@ class FilesystemTest extends FilesystemTestCase
// create symlink to nonexistent dir
rmdir($basePath.'dir');
$this->assertFalse(is_dir($basePath.'dir-link'));
$this->assertFalse('\\' === DIRECTORY_SEPARATOR ? @readlink($basePath.'dir-link') : is_dir($basePath.'dir-link'));
$this->filesystem->remove($basePath);
@ -383,7 +383,7 @@ class FilesystemTest extends FilesystemTestCase
$file = str_repeat('T', 259 - strlen($basePath));
$path = $basePath.$file;
exec('TYPE NUL >>'.$file); // equivalent of touch, we can not use the php touch() here because it suffers from the same limitation
self::$longPathNamesWindows[] = $path; // save this so we can clean up later
$this->longPathNamesWindows[] = $path; // save this so we can clean up later
chdir($oldPath);
$this->filesystem->exists($path);
}
@ -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

@ -17,7 +17,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
{
private $umask;
static protected $longPathNamesWindows = array();
protected $longPathNamesWindows = array();
/**
* @var \Symfony\Component\Filesystem\Filesystem
@ -33,18 +33,11 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
if (!empty(self::$longPathNamesWindows)) {
foreach (self::$longPathNamesWindows as $path) {
exec('DEL '.$path);
}
}
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);
}
}
@ -52,14 +45,21 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->umask = umask(0);
$this->filesystem = new Filesystem();
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
mkdir($this->workspace, 0777, true);
$this->workspace = realpath($this->workspace);
$this->filesystem = new Filesystem();
}
protected function tearDown()
{
if (!empty($this->longPathNamesWindows)) {
foreach ($this->longPathNamesWindows as $path) {
exec('DEL '.$path);
}
$this->longPathNamesWindows = array();
}
$this->filesystem->remove($this->workspace);
umask($this->umask);
}
@ -102,10 +102,6 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
protected function markAsSkippedIfSymlinkIsMissing($relative = false)
{
if (!function_exists('symlink')) {
$this->markTestSkipped('Function symlink is required.');
}
if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) {
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
}

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'),
);
}