mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
Send only integer ID to worker
This commit is contained in:
parent
b7a54c1691
commit
20261f7b77
@ -13,7 +13,7 @@ use Amp\Parallel\Worker\Task;
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class FileTask extends BlockingDriver implements Task {
|
class FileTask extends BlockingDriver implements Task {
|
||||||
const ENV_PREFIX = self::class . '_';
|
const ENV_PREFIX = self::class . '#';
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $operation;
|
private $operation;
|
||||||
@ -38,10 +38,7 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
|
|
||||||
$this->operation = $operation;
|
$this->operation = $operation;
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
|
$this->id = $id;
|
||||||
if ($id !== null) {
|
|
||||||
$this->id = $this->makeId($id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,21 +83,23 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
$file = new BlockingHandle($handle, $path, $mode);
|
$file = new BlockingHandle($handle, $path, $mode);
|
||||||
$id = (int) $handle;
|
$id = (int) $handle;
|
||||||
$size = \fstat($handle)["size"];
|
$size = \fstat($handle)["size"];
|
||||||
$environment->set($this->makeId($id), $file);
|
$environment->set(self::makeId($id), $file);
|
||||||
|
|
||||||
return [$id, $size, $mode];
|
return [$id, $size, $mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->id) {
|
if ($this->id === null) {
|
||||||
throw new FilesystemException("No file ID provided");
|
throw new FilesystemException("No file ID provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$environment->exists($this->id)) {
|
$id = self::makeId($this->id);
|
||||||
throw new FilesystemException("No file handle with the given ID has been opened on the worker");
|
|
||||||
|
if (!$environment->exists($id)) {
|
||||||
|
throw new FilesystemException(\sprintf("No file handle with the ID %d has been opened on the worker", $this->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Amp\File\BlockingHandle $file */
|
/** @var \Amp\File\BlockingHandle $file */
|
||||||
if (!($file = $environment->get($this->id)) instanceof BlockingHandle) {
|
if (!($file = $environment->get($id)) instanceof BlockingHandle) {
|
||||||
throw new FilesystemException("File storage found in inconsistent state");
|
throw new FilesystemException("File storage found in inconsistent state");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +154,7 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function makeId(int $id): string {
|
private static function makeId(int $id): string {
|
||||||
return self::ENV_PREFIX . $id;
|
return self::ENV_PREFIX . $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user