Skip to content

Commit

Permalink
Fix uniquepath on broken symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
vincepare committed Oct 7, 2017
1 parent 03b6700 commit 929f8ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/DirScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function stat($path)
*/
public static function uniquepath($path)
{
if (!file_exists($path)) {
if (!file_exists($path) && !is_link($path)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/dirscan
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class DirScan
*/
public static function uniquepath($path)
{
if (!file_exists($path)) {
if (!file_exists($path) && !is_link($path)) {
return false;
}

Expand Down
15 changes: 13 additions & 2 deletions tests/DirScan/DirScanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public function testUniquePathNotExists()
$this->assertNotEquals(false, $uniquepath);
}

/**
* uniquepath on a broken symlink
*
* @covers \Vincepare\DirScan\DirScan::uniquepath
*/
public function testUniqueBrokenSymlink()
{
$this->assertNotEquals(false, DirScan::uniquepath($this->sandbox.'/ln-broken'));
}

/**
* Directory exploration
*/
Expand Down Expand Up @@ -124,11 +134,12 @@ public function testFullScan()
'/trickynames/false/fuel.txt',
'/trickynames/ ',
'/trickynames/ /fuel.txt',
'/ln-broken',
);
sort($expected);

$this->assertEmpty($reporter->errorStack);
$this->assertCount(40, $reporter->pushStack);
$this->assertCount(41, $reporter->pushStack);
$this->assertSame($expected, $observed);
}

Expand Down Expand Up @@ -168,7 +179,7 @@ public function testDeepDirectoryLoopFull()
$scanner = new DirScan($settings, $reporter);
$scanner->scan($this->sandbox);
$this->assertCount(2, $reporter->errorStack);
$this->assertCount(46, $reporter->pushStack);
$this->assertCount(47, $reporter->pushStack);
$this->assertStringStartsWith('Infinite loop :', $reporter->errorStack[0]['msg']);
$this->assertStringStartsWith('Infinite loop :', $reporter->errorStack[1]['msg']);
}
Expand Down
1 change: 1 addition & 0 deletions tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ln -sv "$PWD/wheels/car/convertible/fuel.txt" ln-file-absolute-fuel
ln -sv wheels/car/convertible/fuel.txt ln-file-relative-fuel
ln -sv "$PWD/wings/seaplane" hulls/ln-dir-absolute-seaplane
(cd hulls && ln -sv ../wings/seaplane ln-dir-relative-seaplane)
ln -sv /no/target/at/all ln-broken

# Directory loop symlinks
ln -sv "$PWD/wheels" wheels/bike/sidecar/ln-dir-loop-absolute
Expand Down

0 comments on commit 929f8ac

Please sign in to comment.