silverstripe / silverstripe-assets

Silverstripe Assets component
BSD 3-Clause "New" or "Revised" License
9 stars 65 forks source link

Don't allow concurrent processes to try creating files with the same name #578

Open sabina-talipova opened 8 months ago

sabina-talipova commented 8 months ago

Description

Currently if two files are uploaded at the same time, they could both have the same name. This would result in an error, though exactly what the error behaviour would be is undetermined.

We should add a read lock in File::onBeforeWrite() to avoid other processes creating files with the same name before this process has a chance to persist in the database.

See: https://github.com/silverstripe/silverstripe-assets/blob/27000f18654ce66e6e92e40bb220121b8d750855/src/File.php#L714