1
0
mirror of https://github.com/danog/file.git synced 2024-11-26 11:54:54 +01:00

Fix UV writing in append mode

This commit is contained in:
Aaron Piotrowski 2019-03-01 10:38:04 -06:00
parent 94f772bd7a
commit 654596edeb
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 21 additions and 4 deletions

View File

@ -176,10 +176,10 @@ class UvHandle implements Handle
} }
} else { } else {
StatCache::clear($this->path); StatCache::clear($this->path);
$newPosition = $this->position + $length; $this->position += $length;
$delta = $newPosition - $this->position; if ($this->position > $this->size) {
$this->position = ($this->mode[0] === "a") ? $this->position : $newPosition; $this->size = $this->position;
$this->size += $delta; }
$deferred->resolve($length); $deferred->resolve($length);
} }
}; };

View File

@ -94,6 +94,23 @@ abstract class HandleTest extends TestCase
}); });
} }
public function testWriteInAppendMode()
{
$this->execute(function () {
$path = Fixture::path() . "/write";
/** @var \Amp\File\Handle $handle */
$handle = yield File\open($path, "a+");
$this->assertSame(0, $handle->tell());
yield $handle->write("bar");
yield $handle->write("foo");
yield $handle->write("baz");
$this->assertSame(9, $handle->tell());
yield $handle->seek(0);
$this->assertSame(0, $handle->tell());
$this->assertSame("barfoobaz", yield $handle->read());
});
}
public function testReadingToEof() public function testReadingToEof()
{ {
$this->execute(function () { $this->execute(function () {