Skip to content

Commit 59d14c7

Browse files
authored
Merge pull request #26 from mmenozzi/mkdir-mode-fix
Fixes wrong mkdir default mode
2 parents 36bb70a + ed5495f commit 59d14c7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function unlink(string $path): Promise {
242242
* @param bool $recursive
243243
* @return \Amp\Promise<null>
244244
*/
245-
function mkdir(string $path, int $mode = 0644, bool $recursive = false): Promise {
245+
function mkdir(string $path, int $mode = 0777, bool $recursive = false): Promise {
246246
return filesystem()->mkdir($path, $mode, $recursive);
247247
}
248248

test/DriverTest.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,11 @@ public function testMkdirRmdir() {
224224

225225
$dir = "{$fixtureDir}/newdir";
226226

227+
\umask(0022);
228+
227229
yield File\mkdir($dir);
228230
$stat = yield File\stat($dir);
229-
$this->assertSame(0644, $stat["mode"] & 0777);
231+
$this->assertSame('0755', $this->getPermissionsFromStat($stat));
230232
yield File\rmdir($dir);
231233
$this->assertNull(yield File\stat($dir));
232234

@@ -235,7 +237,7 @@ public function testMkdirRmdir() {
235237

236238
yield File\mkdir($dir, 0764, true);
237239
$stat = yield File\stat($dir);
238-
$this->assertSame(0764 & (~\umask()), $stat["mode"] & 0777);
240+
$this->assertSame('0744', $this->getPermissionsFromStat($stat));
239241
});
240242
}
241243

@@ -325,4 +327,12 @@ public function testTouch() {
325327
$this->assertTrue($newStat["mtime"] > $oldStat["mtime"]);
326328
});
327329
}
330+
331+
/**
332+
* @param array $stat
333+
* @return string
334+
*/
335+
private function getPermissionsFromStat(array $stat): string {
336+
return \substr(\decoct($stat["mode"]), 1);
337+
}
328338
}

0 commit comments

Comments
 (0)