Skip to content

Commit d2a0b36

Browse files
Merge branch '3.0'
* 3.0: (28 commits) [Console] Fix an autocompletion question helper issue with non-sequentially indexed choices [Process] Fix pipes handling [Finder] Partially revert #17134 to fix a regression Mentioned the deprecation of deep parameters in UPGRADE files [HttpKernel] Fix mem usage when stripping the prod container [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 [HttpFoundation] Fix transient test [HttpFoundation] Add a dependency on the mbstring polyfill [2.7] update readme files for new components add readme files where missing [2.8] update readme files for new components fix lowest TwigBridge deps versions reference form type by name on Symfony 2.7 [EventDispatcher] fix syntax error Don't use reflections when possible Don't use reflections when possible [Form] Update form tests after the ICU data update [Intl] Update tests and the number formatter to match behaviour of the intl extension ... Conflicts: src/Symfony/Component/Ldap/README.md src/Symfony/Component/Security/Core/README.md src/Symfony/Component/Security/Csrf/README.md src/Symfony/Component/Security/Http/README.md
2 parents 5fe7556 + bf32698 commit d2a0b36

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

Filesystem.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,23 @@ public function remove($files)
158158
$files = iterator_to_array($this->toIterator($files));
159159
$files = array_reverse($files);
160160
foreach ($files as $file) {
161+
if (@(unlink($file) || rmdir($file))) {
162+
continue;
163+
}
161164
if (is_link($file)) {
162-
// Workaround https://bugs.php.net/52176
163-
if (!@unlink($file) && !@rmdir($file)) {
164-
$error = error_get_last();
165-
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
166-
}
165+
// See https://bugs.php.net/52176
166+
$error = error_get_last();
167+
throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
167168
} elseif (is_dir($file)) {
168169
$this->remove(new \FilesystemIterator($file));
169170

170171
if (!@rmdir($file)) {
171172
$error = error_get_last();
172173
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
173174
}
174-
} elseif ($this->exists($file)) {
175-
if (!@unlink($file)) {
176-
$error = error_get_last();
177-
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
178-
}
175+
} elseif (file_exists($file)) {
176+
$error = error_get_last();
177+
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
179178
}
180179
}
181180
}
@@ -435,7 +434,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
435434
$target = str_replace($originDir, $targetDir, $file->getPathname());
436435

437436
if ($copyOnWindows) {
438-
if (is_link($file) || is_file($file)) {
437+
if (is_file($file)) {
439438
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
440439
} elseif (is_dir($file)) {
441440
$this->mkdir($target);

Tests/FilesystemTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testCopyCreatesTargetDirectoryIfItDoesNotExist()
156156
$this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
157157
}
158158

159-
public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToNotCopy()
159+
public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy()
160160
{
161161
$sourceFilePath = 'http://symfony.com/images/common/logo/logo_symfony_header.png';
162162
$targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file';
@@ -347,7 +347,7 @@ public function testRemoveCleansInvalidLinks()
347347

348348
// create symlink to nonexistent dir
349349
rmdir($basePath.'dir');
350-
$this->assertFalse(is_dir($basePath.'dir-link'));
350+
$this->assertFalse('\\' === DIRECTORY_SEPARATOR ? @readlink($basePath.'dir-link') : is_dir($basePath.'dir-link'));
351351

352352
$this->filesystem->remove($basePath);
353353

@@ -383,7 +383,7 @@ public function testFilesExistsFails()
383383
$file = str_repeat('T', 259 - strlen($basePath));
384384
$path = $basePath.$file;
385385
exec('TYPE NUL >>'.$file); // equivalent of touch, we can not use the php touch() here because it suffers from the same limitation
386-
self::$longPathNamesWindows[] = $path; // save this so we can clean up later
386+
$this->longPathNamesWindows[] = $path; // save this so we can clean up later
387387
chdir($oldPath);
388388
$this->filesystem->exists($path);
389389
}
@@ -744,6 +744,8 @@ public function testRemoveSymlink()
744744
$this->filesystem->remove($link);
745745

746746
$this->assertTrue(!is_link($link));
747+
$this->assertTrue(!is_file($link));
748+
$this->assertTrue(!is_dir($link));
747749
}
748750

749751
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
@@ -917,7 +919,7 @@ public function testMirrorCopiesLinks()
917919
$this->filesystem->mirror($sourcePath, $targetPath);
918920

919921
$this->assertTrue(is_dir($targetPath));
920-
$this->assertFileEquals($sourcePath.'file1', $targetPath.DIRECTORY_SEPARATOR.'link1');
922+
$this->assertFileEquals($sourcePath.'file1', $targetPath.'link1');
921923
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
922924
}
923925

@@ -937,7 +939,7 @@ public function testMirrorCopiesLinkedDirectoryContents()
937939
$this->filesystem->mirror($sourcePath, $targetPath);
938940

939941
$this->assertTrue(is_dir($targetPath));
940-
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
942+
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt');
941943
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
942944
}
943945

@@ -961,7 +963,7 @@ public function testMirrorCopiesRelativeLinkedContents()
961963
$this->filesystem->mirror($sourcePath, $targetPath);
962964

963965
$this->assertTrue(is_dir($targetPath));
964-
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
966+
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt');
965967
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
966968
$this->assertEquals('\\' === DIRECTORY_SEPARATOR ? realpath($sourcePath.'\nested') : 'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
967969
}

Tests/FilesystemTestCase.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
1717
{
1818
private $umask;
1919

20-
static protected $longPathNamesWindows = array();
20+
protected $longPathNamesWindows = array();
2121

2222
/**
2323
* @var \Symfony\Component\Filesystem\Filesystem
@@ -33,33 +33,33 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
3333

3434
public static function setUpBeforeClass()
3535
{
36-
if (!empty(self::$longPathNamesWindows)) {
37-
foreach (self::$longPathNamesWindows as $path) {
38-
exec('DEL '.$path);
39-
}
40-
}
41-
4236
if ('\\' === DIRECTORY_SEPARATOR && null === self::$symlinkOnWindows) {
4337
$target = tempnam(sys_get_temp_dir(), 'sl');
4438
$link = sys_get_temp_dir().'/sl'.microtime(true).mt_rand();
45-
if (self::$symlinkOnWindows = @symlink($target, $link)) {
46-
unlink($link);
47-
}
39+
self::$symlinkOnWindows = @symlink($target, $link) && is_link($link);
40+
@unlink($link);
4841
unlink($target);
4942
}
5043
}
5144

5245
protected function setUp()
5346
{
5447
$this->umask = umask(0);
48+
$this->filesystem = new Filesystem();
5549
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
5650
mkdir($this->workspace, 0777, true);
5751
$this->workspace = realpath($this->workspace);
58-
$this->filesystem = new Filesystem();
5952
}
6053

6154
protected function tearDown()
6255
{
56+
if (!empty($this->longPathNamesWindows)) {
57+
foreach ($this->longPathNamesWindows as $path) {
58+
exec('DEL '.$path);
59+
}
60+
$this->longPathNamesWindows = array();
61+
}
62+
6363
$this->filesystem->remove($this->workspace);
6464
umask($this->umask);
6565
}
@@ -102,10 +102,6 @@ protected function getFileGroup($filepath)
102102

103103
protected function markAsSkippedIfSymlinkIsMissing($relative = false)
104104
{
105-
if (!function_exists('symlink')) {
106-
$this->markTestSkipped('Function symlink is required.');
107-
}
108-
109105
if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) {
110106
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
111107
}

0 commit comments

Comments
 (0)