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:
parent
94f772bd7a
commit
654596edeb
@ -176,10 +176,10 @@ class UvHandle implements Handle
|
||||
}
|
||||
} else {
|
||||
StatCache::clear($this->path);
|
||||
$newPosition = $this->position + $length;
|
||||
$delta = $newPosition - $this->position;
|
||||
$this->position = ($this->mode[0] === "a") ? $this->position : $newPosition;
|
||||
$this->size += $delta;
|
||||
$this->position += $length;
|
||||
if ($this->position > $this->size) {
|
||||
$this->size = $this->position;
|
||||
}
|
||||
$deferred->resolve($length);
|
||||
}
|
||||
};
|
||||
|
@ -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()
|
||||
{
|
||||
$this->execute(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user