Skip to content

Commit 6612ae6

Browse files
committed
EioDriver and UvDriver did not pass O_TRUNC in file\put
Also prepare tag 0.1.3
1 parent ada8667 commit 6612ae6

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 0.1.3
2+
3+
- Add recursive mkdir()
4+
- EioDriver and UvDriver now pass O_TRUNC in file\put()
5+
16
### 0.1.2
27

38
- Make UvHandle throw FilesystemException instead of \RuntimeException

lib/EioDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private function onGetRead($fhAndPromisor, $result, $req) {
538538
* {@inheritdoc}
539539
*/
540540
public function put($path, $contents) {
541-
$flags = \EIO_O_RDWR | \EIO_O_CREAT;
541+
$flags = \EIO_O_RDWR | \EIO_O_CREAT | \EIO_O_TRUNC;
542542
$mode = \EIO_S_IRUSR | \EIO_S_IWUSR | \EIO_S_IXUSR;
543543
$priority = \EIO_PRI_DEFAULT;
544544

lib/UvDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public function put($path, $contents) {
515515
}
516516

517517
private function doPut($path, $contents): \Generator {
518-
$flags = \UV::O_WRONLY | \UV::O_CREAT;
518+
$flags = \UV::O_WRONLY | \UV::O_CREAT | \UV::O_TRUNC;
519519
$mode = \UV::S_IRWXU | \UV::S_IRUSR;
520520
$this->reactor->addRef();
521521
$promise = $this->doFsOpen($path, $flags, $mode);

test/DriverTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,21 @@ public function testRename() {
243243
});
244244
}
245245

246+
public function testPutTruncates() {
247+
amp\run(function () {
248+
$fixturePath = self::getFixturePath() . "/trunc";
249+
$contents = "long data";
250+
$short = "data";
251+
252+
yield file\put($fixturePath, $contents);
253+
yield file\put($fixturePath, $short);
254+
$contents2 = (yield file\get($fixturePath));
255+
yield file\unlink($fixturePath);
256+
257+
$this->assertSame($short, $contents2);
258+
});
259+
}
260+
246261
public function testUnlink() {
247262
amp\run(function () {
248263
$fixtureDir = self::getFixturePath();

0 commit comments

Comments
 (0)