From 6612ae6757d4719492ed8b34ea6181ff67cfbed1 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 1 Oct 2016 18:43:52 +0100 Subject: [PATCH] EioDriver and UvDriver did not pass O_TRUNC in file\put Also prepare tag 0.1.3 --- CHANGELOG | 5 +++++ lib/EioDriver.php | 2 +- lib/UvDriver.php | 2 +- test/DriverTest.php | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3c2efb1..5dcc569 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +### 0.1.3 + +- Add recursive mkdir() +- EioDriver and UvDriver now pass O_TRUNC in file\put() + ### 0.1.2 - Make UvHandle throw FilesystemException instead of \RuntimeException diff --git a/lib/EioDriver.php b/lib/EioDriver.php index e0285bb..ce3213a 100644 --- a/lib/EioDriver.php +++ b/lib/EioDriver.php @@ -538,7 +538,7 @@ class EioDriver implements Driver { * {@inheritdoc} */ public function put($path, $contents) { - $flags = \EIO_O_RDWR | \EIO_O_CREAT; + $flags = \EIO_O_RDWR | \EIO_O_CREAT | \EIO_O_TRUNC; $mode = \EIO_S_IRUSR | \EIO_S_IWUSR | \EIO_S_IXUSR; $priority = \EIO_PRI_DEFAULT; diff --git a/lib/UvDriver.php b/lib/UvDriver.php index c946b22..ab92d73 100644 --- a/lib/UvDriver.php +++ b/lib/UvDriver.php @@ -515,7 +515,7 @@ class UvDriver implements Driver { } private function doPut($path, $contents): \Generator { - $flags = \UV::O_WRONLY | \UV::O_CREAT; + $flags = \UV::O_WRONLY | \UV::O_CREAT | \UV::O_TRUNC; $mode = \UV::S_IRWXU | \UV::S_IRUSR; $this->reactor->addRef(); $promise = $this->doFsOpen($path, $flags, $mode); diff --git a/test/DriverTest.php b/test/DriverTest.php index edc1b16..b6f5bac 100644 --- a/test/DriverTest.php +++ b/test/DriverTest.php @@ -243,6 +243,21 @@ abstract class DriverTest extends \PHPUnit_Framework_TestCase { }); } + public function testPutTruncates() { + amp\run(function () { + $fixturePath = self::getFixturePath() . "/trunc"; + $contents = "long data"; + $short = "data"; + + yield file\put($fixturePath, $contents); + yield file\put($fixturePath, $short); + $contents2 = (yield file\get($fixturePath)); + yield file\unlink($fixturePath); + + $this->assertSame($short, $contents2); + }); + } + public function testUnlink() { amp\run(function () { $fixtureDir = self::getFixturePath();