From 929f8ac8d1f11f83fc30dd7320e74c8d12ca170d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Par=C3=A9?= Date: Sat, 7 Oct 2017 18:33:44 +0200 Subject: [PATCH] Fix uniquepath on broken symlink --- src/DirScan.php | 2 +- src/legacy/dirscan | 2 +- tests/DirScan/DirScanTest.php | 15 +++++++++++++-- tests/setup.sh | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/DirScan.php b/src/DirScan.php index bc24fdb..4aad03f 100644 --- a/src/DirScan.php +++ b/src/DirScan.php @@ -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; } diff --git a/src/legacy/dirscan b/src/legacy/dirscan index 53b6f28..268215e 100755 --- a/src/legacy/dirscan +++ b/src/legacy/dirscan @@ -292,7 +292,7 @@ class DirScan */ public static function uniquepath($path) { - if (!file_exists($path)) { + if (!file_exists($path) && !is_link($path)) { return false; } diff --git a/tests/DirScan/DirScanTest.php b/tests/DirScan/DirScanTest.php index 32bf35c..51e82f8 100644 --- a/tests/DirScan/DirScanTest.php +++ b/tests/DirScan/DirScanTest.php @@ -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 */ @@ -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); } @@ -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']); } diff --git a/tests/setup.sh b/tests/setup.sh index e16c2b0..7807b9d 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -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