@@ -106,11 +106,7 @@ public static function start(
106
106
self ::$ pharCopy = \sys_get_temp_dir () . "/phar- " . \bin2hex (\random_bytes (10 )) . ".phar " ;
107
107
\copy (\Phar::running (false ), self ::$ pharCopy );
108
108
109
- \register_shutdown_function (static function (): void {
110
- if (self ::$ pharCopy !== null ) {
111
- @\unlink (self ::$ pharCopy );
112
- }
113
- });
109
+ \register_shutdown_function (static fn () => self ::unlinkExternalCopy (self ::$ pharCopy ));
114
110
115
111
$ path = "phar:// " . self ::$ pharCopy . "/ " . \substr ($ path , \strlen (\Phar::running (true )));
116
112
}
@@ -121,11 +117,7 @@ public static function start(
121
117
self ::$ pharScriptPath = $ scriptPath = \sys_get_temp_dir () . "/amp-process-runner- " . $ suffix . ".php " ;
122
118
\file_put_contents ($ scriptPath , $ contents );
123
119
124
- \register_shutdown_function (static function (): void {
125
- if (self ::$ pharScriptPath !== null ) {
126
- @\unlink (self ::$ pharScriptPath );
127
- }
128
- });
120
+ \register_shutdown_function (static fn () => self ::unlinkExternalCopy (self ::$ pharScriptPath ));
129
121
}
130
122
131
123
// Monkey-patch the script path in the same way, only supported if the command is given as array.
@@ -176,6 +168,20 @@ public static function start(
176
168
return new self ($ process , $ ipcChannel , $ resultChannel );
177
169
}
178
170
171
+ private static function unlinkExternalCopy (?string $ filepath ): void
172
+ {
173
+ if ($ filepath === null ) {
174
+ return ;
175
+ }
176
+
177
+ \set_error_handler (static fn () => true );
178
+ try {
179
+ \unlink ($ filepath );
180
+ } finally {
181
+ \restore_error_handler ();
182
+ }
183
+ }
184
+
179
185
/**
180
186
* @return non-empty-list<string>
181
187
*/
0 commit comments