Skip to content

Commit 724cd19

Browse files
committed
fix(file): respect file locks during reads
1 parent 746ade2 commit 724cd19

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/support/src/Filesystem/functions.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ function read_file(string $filename): string
120120
throw Exceptions\PathWasNotReadable::forFile($filename);
121121
}
122122

123-
[$result, $message] = box(static fn (): false|string => file_get_contents($filename));
123+
[$result, $message] = box(static function () use ($filename): false|string {
124+
$file_pointer = fopen($filename, 'rb');
125+
flock($file_pointer, LOCK_SH);
126+
$contents = file_get_contents($filename);
127+
flock($file_pointer, LOCK_UN);
128+
fclose($file_pointer);
129+
130+
return $contents;
131+
});
124132

125133
if (false === $result) {
126134
throw new Exceptions\RuntimeException(sprintf(

0 commit comments

Comments
 (0)