From ed5495f0840a526a73e1b0d9c0fa8edf1f8edc48 Mon Sep 17 00:00:00 2001 From: Manuele Menozzi Date: Thu, 15 Mar 2018 18:35:10 +0100 Subject: [PATCH] Fixes wrong mkdir default mode --- lib/functions.php | 2 +- test/DriverTest.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index e552b9c..2fef7ce 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -242,7 +242,7 @@ function unlink(string $path): Promise { * @param bool $recursive * @return \Amp\Promise */ -function mkdir(string $path, int $mode = 0644, bool $recursive = false): Promise { +function mkdir(string $path, int $mode = 0777, bool $recursive = false): Promise { return filesystem()->mkdir($path, $mode, $recursive); } diff --git a/test/DriverTest.php b/test/DriverTest.php index cde6aa8..b49435e 100644 --- a/test/DriverTest.php +++ b/test/DriverTest.php @@ -224,9 +224,11 @@ abstract class DriverTest extends TestCase { $dir = "{$fixtureDir}/newdir"; + \umask(0022); + yield File\mkdir($dir); $stat = yield File\stat($dir); - $this->assertSame(0644, $stat["mode"] & 0777); + $this->assertSame('0755', $this->getPermissionsFromStat($stat)); yield File\rmdir($dir); $this->assertNull(yield File\stat($dir)); @@ -235,7 +237,7 @@ abstract class DriverTest extends TestCase { yield File\mkdir($dir, 0764, true); $stat = yield File\stat($dir); - $this->assertSame(0764 & (~\umask()), $stat["mode"] & 0777); + $this->assertSame('0744', $this->getPermissionsFromStat($stat)); }); } @@ -325,4 +327,12 @@ abstract class DriverTest extends TestCase { $this->assertTrue($newStat["mtime"] > $oldStat["mtime"]); }); } + + /** + * @param array $stat + * @return string + */ + private function getPermissionsFromStat(array $stat): string { + return \substr(\decoct($stat["mode"]), 1); + } }