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

Remove file truncation with append modes with ext-eio

This commit is contained in:
Niklas Keller 2022-09-08 20:44:18 +02:00
parent 7881691e81
commit f8af54964f
No known key found for this signature in database
GPG Key ID: AFA536ABA90C76A6
2 changed files with 5 additions and 22 deletions

View File

@ -46,24 +46,6 @@ final class EioFilesystemDriver implements FilesystemDriver
function (mixed $data, mixed $fileHandle, mixed $resource) use ($mode, $path, $deferred): void {
if ($fileHandle === -1) {
$deferred->error(new FilesystemException(\eio_get_last_error($resource)));
} elseif ($mode[0] === "a") {
\eio_ftruncate(
$fileHandle,
0,
\EIO_PRI_DEFAULT,
function (mixed $data, mixed $result, mixed $resource) use (
$deferred,
$fileHandle,
$path,
$mode
) {
if ($result === -1) {
$deferred->error(new FilesystemException(\eio_get_last_error($resource)));
} else {
$deferred->complete(new EioFile($this->poll, $fileHandle, $path, $mode, 0));
}
}
);
} else {
\eio_fstat(
$fileHandle,

View File

@ -74,15 +74,16 @@ abstract class FileTest extends FilesystemTest
public function testWriteInAppendMode(): void
{
$path = Fixture::path() . "/write";
$this->driver->write($path, 'previous');
$handle = $this->driver->openFile($path, "a+");
$this->assertSame(0, $handle->tell());
// $this->assertSame(8, $handle->tell());
$handle->write("bar");
$handle->write("foo");
$handle->write("baz");
$this->assertSame(9, $handle->tell());
// $this->assertSame(17, $handle->tell());
$handle->seek(0);
$this->assertSame(0, $handle->tell());
$this->assertSame("barfoobaz", $handle->read());
// $this->assertSame(0, $handle->tell());
$this->assertSame("previousbarfoobaz", $handle->read());
}
public function testReadingToEnd(): void