1
0
mirror of https://github.com/danog/file.git synced 2024-11-30 04:19:39 +01:00

Fix #11 - use 0666 default permissions and rely on umask()

This commit is contained in:
Bob Weinand 2016-10-03 12:17:05 +02:00
parent c822717106
commit cf7a966900
4 changed files with 21 additions and 13 deletions

View File

@ -203,7 +203,7 @@ class BlockingDriver implements Driver {
/**
* {@inheritdoc}
*/
public function mkdir($path, $mode = 0644, $recursive = false) {
public function mkdir($path, $mode = 0666, $recursive = false) {
return new Success((bool) @\mkdir($path, $mode, $recursive));
}

View File

@ -71,7 +71,7 @@ class EioDriver implements Driver {
"Invalid open mode"
));
}
$chmod = ($flags & \EIO_O_CREAT) ? 0644 : 0;
$chmod = ($flags & \EIO_O_CREAT) ? 0666 : 0;
\call_user_func($this->incrementor, 1);
$promisor = new Deferred;
$openArr = [$mode, $path, $promisor];
@ -356,7 +356,7 @@ class EioDriver implements Driver {
/**
* {@inheritdoc}
*/
public function mkdir($path, $mode = 0644, $recursive = false) {
public function mkdir($path, $mode = 0666, $recursive = false) {
\call_user_func($this->incrementor, 1);
$promisor = new Deferred;
$priority = \EIO_PRI_DEFAULT;
@ -538,8 +538,8 @@ class EioDriver implements Driver {
* {@inheritdoc}
*/
public function put($path, $contents) {
$flags = \EIO_O_RDWR | \EIO_O_CREAT | \EIO_O_TRUNC;
$mode = \EIO_S_IRUSR | \EIO_S_IWUSR | \EIO_S_IXUSR;
$flags = \EIO_O_WRONLY | \EIO_O_CREAT | \EIO_O_TRUNC;
$mode = 0666;
$priority = \EIO_PRI_DEFAULT;
\call_user_func($this->incrementor, 1);

View File

@ -38,7 +38,7 @@ class UvDriver implements Driver {
"Invalid open mode"
));
}
$chmod = ($flags & \UV::O_CREAT) ? 0644 : 0;
$chmod = ($flags & \UV::O_CREAT) ? 0666 : 0;
$this->reactor->addRef();
$promisor = new Deferred;
$openArr = [$mode, $path, $promisor];
@ -300,7 +300,7 @@ class UvDriver implements Driver {
/**
* {@inheritdoc}
*/
public function mkdir($path, $mode = 0644, $recursive = false) {
public function mkdir($path, $mode = 0666, $recursive = false) {
$this->reactor->addRef();
$promisor = new Deferred;
@ -516,7 +516,7 @@ class UvDriver implements Driver {
private function doPut($path, $contents): \Generator {
$flags = \UV::O_WRONLY | \UV::O_CREAT | \UV::O_TRUNC;
$mode = \UV::S_IRWXU | \UV::S_IRUSR;
$mode = 0666;
$this->reactor->addRef();
$promise = $this->doFsOpen($path, $flags, $mode);
if (!$fh = (yield $promise)) {

View File

@ -7,6 +7,7 @@ use Amp\File as file;
abstract class DriverTest extends \PHPUnit_Framework_TestCase {
private static $fixtureId;
private static $umask;
private static function getFixturePath() {
if (empty(self::$fixtureId)) {
@ -33,6 +34,7 @@ abstract class DriverTest extends \PHPUnit_Framework_TestCase {
$fixtureDir = self::getFixturePath();
self::clearFixtureDir();
self::$umask = umask(0022);
if (!\mkdir($fixtureDir, $mode = 0777, $recursive = true)) {
throw new \RuntimeException(
@ -53,6 +55,7 @@ abstract class DriverTest extends \PHPUnit_Framework_TestCase {
public static function tearDownAfterClass() {
self::clearFixtureDir();
umask(self::$umask);
}
protected function setUp() {
@ -258,12 +261,15 @@ abstract class DriverTest extends \PHPUnit_Framework_TestCase {
});
}
public function testUnlink() {
public function testPermsAndUnlink() {
amp\run(function () {
$fixtureDir = self::getFixturePath();
$toUnlink = "{$fixtureDir}/unlink";
$mask = umask(062);
yield file\put($toUnlink, "unlink me");
$this->assertTrue((bool) (yield file\stat($toUnlink)));
umask($mask);
$stat = yield file\stat($toUnlink);
$this->assertTrue(($stat["mode"] & 0777) == 0604);
yield file\unlink($toUnlink);
$this->assertNull(yield file\stat($toUnlink));
});
@ -276,14 +282,16 @@ abstract class DriverTest extends \PHPUnit_Framework_TestCase {
$dir = "{$fixtureDir}/newdir";
yield file\mkdir($dir);
$this->assertNotNull(yield file\stat($dir));
$stat = yield file\stat($dir);
$this->assertTrue(($stat["mode"] & 0777) == 0644);
yield file\rmdir($dir);
$this->assertNull(yield file\stat($dir));
$dir = "{$fixtureDir}/newdir/with/recursive/creation";
yield file\mkdir($dir, 0744, true);
$this->assertNotNull(yield file\stat($dir));
yield file\mkdir($dir, 0764, true); // the umask is 022 by default
$stat = yield file\stat($dir);
$this->assertTrue(($stat["mode"] & 0777) == 0744);
});
}