Skip to content

Commit 20261f7

Browse files
committed
Send only integer ID to worker
1 parent b7a54c1 commit 20261f7

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/Internal/FileTask.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @internal
1414
*/
1515
class FileTask extends BlockingDriver implements Task {
16-
const ENV_PREFIX = self::class . '_';
16+
const ENV_PREFIX = self::class . '#';
1717

1818
/** @var string */
1919
private $operation;
@@ -38,10 +38,7 @@ public function __construct(string $operation, array $args = [], int $id = null)
3838

3939
$this->operation = $operation;
4040
$this->args = $args;
41-
42-
if ($id !== null) {
43-
$this->id = $this->makeId($id);
44-
}
41+
$this->id = $id;
4542
}
4643

4744
/**
@@ -86,21 +83,23 @@ public function run(Environment $environment) {
8683
$file = new BlockingHandle($handle, $path, $mode);
8784
$id = (int) $handle;
8885
$size = \fstat($handle)["size"];
89-
$environment->set($this->makeId($id), $file);
86+
$environment->set(self::makeId($id), $file);
9087

9188
return [$id, $size, $mode];
9289
}
9390

94-
if (null === $this->id) {
91+
if ($this->id === null) {
9592
throw new FilesystemException("No file ID provided");
9693
}
9794

98-
if (!$environment->exists($this->id)) {
99-
throw new FilesystemException("No file handle with the given ID has been opened on the worker");
95+
$id = self::makeId($this->id);
96+
97+
if (!$environment->exists($id)) {
98+
throw new FilesystemException(\sprintf("No file handle with the ID %d has been opened on the worker", $this->id));
10099
}
101100

102101
/** @var \Amp\File\BlockingHandle $file */
103-
if (!($file = $environment->get($this->id)) instanceof BlockingHandle) {
102+
if (!($file = $environment->get($id)) instanceof BlockingHandle) {
104103
throw new FilesystemException("File storage found in inconsistent state");
105104
}
106105

@@ -155,7 +154,7 @@ public function run(Environment $environment) {
155154
*
156155
* @return string
157156
*/
158-
private function makeId(int $id): string {
157+
private static function makeId(int $id): string {
159158
return self::ENV_PREFIX . $id;
160159
}
161160
}

0 commit comments

Comments
 (0)