1
0
mirror of https://github.com/danog/file.git synced 2025-01-22 13:21:13 +01:00

Fix filesize after write in ParallelFile

This commit is contained in:
Aaron Piotrowski 2022-11-23 14:46:07 -06:00
parent a86be72957
commit 1dfa6454e9
No known key found for this signature in database
GPG Key ID: 5B456E6AABA44A63

View File

@ -122,6 +122,7 @@ final class ParallelFile implements File
try {
$this->worker->execute(new Internal\FileTask('ftruncate', [$size], $this->id));
$this->size = $size;
} catch (TaskFailureException $exception) {
throw new StreamException("Reading from the file failed", 0, $exception);
} catch (WorkerException $exception) {
@ -187,6 +188,7 @@ final class ParallelFile implements File
try {
$this->worker->execute(new Internal\FileTask('fwrite', [$bytes], $this->id));
$this->position += \strlen($bytes);
$this->size = \max($this->position, $this->size);
} catch (TaskFailureException $exception) {
throw new StreamException("Writing to the file failed", 0, $exception);
} catch (WorkerException $exception) {
@ -223,9 +225,7 @@ final class ParallelFile implements File
new Internal\FileTask('fseek', [$position, $whence], $this->id)
);
if ($this->position > $this->size) {
$this->size = $this->position;
}
$this->size = \max($this->position, $this->size);
return $this->position;
} catch (TaskFailureException $exception) {