Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13aa515

Browse filesBrowse files
committed
merged branch jakzal/FilesystemTests (PR #3811)
Commits ------- 100e97e [Filesystem] Fixed warnings in makePathRelative(). f5f5c21 [Filesystem] Fixed typos in the docblocks. d4243a2 [Filesystem] Fixed a bug in remove being unable to remove symlinks to unexisting file or directory. 11a676d [Filesystem] Added unit tests for mirror method. 8c94069 [Filesystem] Added unit tests for isAbsolutePath method. 2ee4b88 [Filesystem] Added unit tests for makePathRelative method. 21860cb [Filesystem] Added unit tests for symlink method. a041feb [Filesystem] Added unit tests for rename method. 8071859 [Filesystem] Added unit tests for chmod method. bba0080 [Filesystem] Added unit tests for remove method. 8e861b7 [Filesystem] Introduced workspace directory to limit complexity of tests. a91e200 [Filesystem] Added unit tests for touch method. 7e297db [Filesystem] Added unit tests for mkdir method. 6ac5486 [Filesystem] Added unit tests for copy method. 1c833e7 [Filesystem] Added missing docblock comment. Discussion ---------- [Filesystem] Fixed a bug in remove() being unable to unlink broken symlinks While working on test coverage for Filesystem class I discovered a bug in remove() method. Before removing a file a check is made if it exists: if (!file_exists($file)) { continue; } Problem is [file_exists()](http://php.net/file_exists) returns false if link's target file doesn't exist. Therefore remove() will fail to delete a directory containing a broken link. Solution is to handle links a bit different: if (!file_exists($file) && !is_link($file)) { continue; } Additionally, this PR improves test coverage of Filesystem component. Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes --------------------------------------------------------------------------- by cordoval at 2012-04-07T00:55:59Z ✌.|•͡˘‿•͡˘|.✌ --------------------------------------------------------------------------- by fabpot at 2012-04-07T06:12:34Z Tests do not pass for me: PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from /Users/fabien/work/symfony/git/symfony/phpunit.xml.dist .........................EE....... Time: 0 seconds, Memory: 5.25Mb There were 2 errors: 1) Symfony\Component\Filesystem\Tests\FilesystemTest::testMakePathRelative with data set #0 ('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../') Uninitialized string offset: 29 .../rc/Symfony/Component/Filesystem/Filesystem.php:183 .../rc/Symfony/Component/Filesystem/Tests/FilesystemTest.php:434 2) Symfony\Component\Filesystem\Tests\FilesystemTest::testMakePathRelative with data set #1 ('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../') Uninitialized string offset: 16 .../rc/Symfony/Component/Filesystem/Filesystem.php:183 .../rc/Symfony/Component/Filesystem/Tests/FilesystemTest.php:434 FAILURES! Tests: 34, Assertions: 67, Errors: 2. --------------------------------------------------------------------------- by jakzal at 2012-04-07T07:26:15Z Sorry for this. For some reason my PHP error reporting level was to low to catch this... Should be fixed now but I needed to modify the makePathRelative() (this bug existed before).
2 parents e7dbc38 + 100e97e commit 13aa515
Copy full SHA for 13aa515

File tree

2 files changed

+534
-6
lines changed
Filter options

2 files changed

+534
-6
lines changed

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function mkdir($dirs, $mode = 0777)
6969
/**
7070
* Creates empty files.
7171
*
72-
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
72+
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to create
7373
*/
7474
public function touch($files)
7575
{
@@ -88,7 +88,7 @@ public function remove($files)
8888
$files = iterator_to_array($this->toIterator($files));
8989
$files = array_reverse($files);
9090
foreach ($files as $file) {
91-
if (!file_exists($file)) {
91+
if (!file_exists($file) && !is_link($file)) {
9292
continue;
9393
}
9494

@@ -105,7 +105,7 @@ public function remove($files)
105105
/**
106106
* Change mode for an array of files or directories.
107107
*
108-
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
108+
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change mode
109109
* @param integer $mode The new mode
110110
* @param integer $umask The mode mask (octal)
111111
*/
@@ -171,16 +171,16 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
171171
/**
172172
* Given an existing path, convert it to a path relative to a given starting path
173173
*
174-
* @var string Absolute path of target
175-
* @var string Absolute path where traversal begins
174+
* @param string $endPath Absolute path of target
175+
* @param string $startPath Absolute path where traversal begins
176176
*
177177
* @return string Path of target relative to starting path
178178
*/
179179
public function makePathRelative($endPath, $startPath)
180180
{
181181
// Find for which character the the common path stops
182182
$offset = 0;
183-
while ($startPath[$offset] === $endPath[$offset]) {
183+
while (isset($startPath[$offset]) && isset($endPath[$offset]) && $startPath[$offset] === $endPath[$offset]) {
184184
$offset++;
185185
}
186186

@@ -264,6 +264,11 @@ public function isAbsolutePath($file)
264264
return false;
265265
}
266266

267+
/**
268+
* @param mixed $files
269+
*
270+
* @return \Traversable
271+
*/
267272
private function toIterator($files)
268273
{
269274
if (!$files instanceof \Traversable) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.