From 3e5da2b245f42fc88a54f18ab3f1c009f257ad44 Mon Sep 17 00:00:00 2001 From: Andrew Mackrodt Date: Wed, 18 Jul 2018 06:00:53 +0100 Subject: [PATCH] Fixes invalid stat result in UvDriver --- lib/UvDriver.php | 8 ++++++++ test/DriverTest.php | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/UvDriver.php b/lib/UvDriver.php index af698c2..0783365 100644 --- a/lib/UvDriver.php +++ b/lib/UvDriver.php @@ -123,6 +123,14 @@ class UvDriver implements Driver { if (empty($fh)) { $stat = null; } else { + // link is not a valid stat type but returned by the uv extension + // change link to nlink + if (isset($stat['link'])) { + $stat['nlink'] = $stat['link']; + + unset($stat['link']); + } + StatCache::set($path, $stat); } diff --git a/test/DriverTest.php b/test/DriverTest.php index b49435e..7523e9b 100644 --- a/test/DriverTest.php +++ b/test/DriverTest.php @@ -74,6 +74,7 @@ abstract class DriverTest extends TestCase { $fixtureDir = Fixture::path(); $stat = (yield File\stat("{$fixtureDir}/small.txt")); $this->assertInternalType("array", $stat); + $this->assertStatSame(\stat("{$fixtureDir}/small.txt"), $stat); }); } @@ -82,6 +83,7 @@ abstract class DriverTest extends TestCase { $fixtureDir = Fixture::path(); $stat = (yield File\stat("{$fixtureDir}/dir")); $this->assertInternalType("array", $stat); + $this->assertStatSame(\stat("{$fixtureDir}/dir"), $stat); }); } @@ -328,6 +330,24 @@ abstract class DriverTest extends TestCase { }); } + private function assertStatSame(array $expected, array $actual) { + $filter = function (array $stat) { + $filtered = \array_filter( + $stat, + function (string $key): bool { + return !\is_numeric($key); + }, + ARRAY_FILTER_USE_KEY + ); + + ksort($filtered); + + return $filtered; + }; + + $this->assertSame($filter($expected), $filter($actual)); + } + /** * @param array $stat * @return string