13
13
* @internal
14
14
*/
15
15
class FileTask extends BlockingDriver implements Task {
16
- const ENV_PREFIX = self ::class . '_ ' ;
16
+ const ENV_PREFIX = self ::class . '# ' ;
17
17
18
18
/** @var string */
19
19
private $ operation ;
@@ -38,10 +38,7 @@ public function __construct(string $operation, array $args = [], int $id = null)
38
38
39
39
$ this ->operation = $ operation ;
40
40
$ this ->args = $ args ;
41
-
42
- if ($ id !== null ) {
43
- $ this ->id = $ this ->makeId ($ id );
44
- }
41
+ $ this ->id = $ id ;
45
42
}
46
43
47
44
/**
@@ -86,21 +83,23 @@ public function run(Environment $environment) {
86
83
$ file = new BlockingHandle ($ handle , $ path , $ mode );
87
84
$ id = (int ) $ handle ;
88
85
$ size = \fstat ($ handle )["size " ];
89
- $ environment ->set ($ this -> makeId ($ id ), $ file );
86
+ $ environment ->set (self :: makeId ($ id ), $ file );
90
87
91
88
return [$ id , $ size , $ mode ];
92
89
}
93
90
94
- if (null === $ this ->id ) {
91
+ if ($ this ->id === null ) {
95
92
throw new FilesystemException ("No file ID provided " );
96
93
}
97
94
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 ));
100
99
}
101
100
102
101
/** @var \Amp\File\BlockingHandle $file */
103
- if (!($ file = $ environment ->get ($ this -> id )) instanceof BlockingHandle) {
102
+ if (!($ file = $ environment ->get ($ id )) instanceof BlockingHandle) {
104
103
throw new FilesystemException ("File storage found in inconsistent state " );
105
104
}
106
105
@@ -155,7 +154,7 @@ public function run(Environment $environment) {
155
154
*
156
155
* @return string
157
156
*/
158
- private function makeId (int $ id ): string {
157
+ private static function makeId (int $ id ): string {
159
158
return self ::ENV_PREFIX . $ id ;
160
159
}
161
160
}
0 commit comments