flysystem icon indicating copy to clipboard operation
flysystem copied to clipboard

Local Adapter: Lock files during read when LOCK_EX flag is set

Open MichaelRoosz opened this issue 2 years ago • 0 comments

Currently the Local Adapter will lock files with the "LOCK_EX" flag by default during write. However, during read locks are completely ignored.

This PR will set read (shared) locks during reads. This will fix reading corrupted data while a write is happening.

I encountered this issue (corrupted files) while using the php-cache library, which is using flystem for read and write operations ( https://github.com/php-cache/cache/blob/master/src/Adapter/Filesystem/FilesystemCachePool.php#L19 ).

Note: in readStream() the lock is obtained but never released, but this should be fine, because it will be automatically released during "fclose()".

MichaelRoosz avatar May 31 '22 07:05 MichaelRoosz