[Filesystem] Fixed relative path calculation for end path which is a subdirectory of the start path.

This commit is contained in:
Jakub Zalas 2012-04-07 21:52:26 +01:00
parent bc93787a0d
commit 22e2ad80c9
2 changed files with 2 additions and 2 deletions

View File

@ -186,7 +186,7 @@ class Filesystem
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
$diffPath = trim(substr($startPath, $offset), DIRECTORY_SEPARATOR);
$depth = substr_count($diffPath, DIRECTORY_SEPARATOR) + 1;
$depth = strlen($diffPath) > 0 ? substr_count($diffPath, DIRECTORY_SEPARATOR) + 1 : 0;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);

View File

@ -448,7 +448,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', '../src/Symfony/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
);
// fix directory separator