flysystem: Exception thrown by Local driver attempting to create directory in quick succession

I have an application where I allow a user to pick multiple files for upload from a web form. These are then submitted individually and asynchronously using jQuery and HTML FormData.

If I have several small files submitting at once, it is possible that the server arrives at Local::ensureDirectory() almost simultaneously and the if ( ! is_dir($root)) check returns an incorrect result.

This can result in an ErrorException “mkdir(): File exists”. I’m not sure you can reproduce the error without my app, but steps would be:

  • Laravel 5.2 app running on local Vagrant Homestead instance with PHP7
  • Multiple async submissions to a route which should result in creation of a directory that does not yet exist
  • Produces exception below:

screen shot 2016-03-24 at 13 40 53

This may well be a PHP problem and/or Vagrant not running fast enough in a local environment, but I wonder if it’s possible to mitigate, perhaps wrapping in try/catch that looks for the “File exists” message? I’ve checked the Exception thrown for other problems such as permissions and unfortunately it’s identical apart from the message - and I guess that may change in different languages.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 20 (9 by maintainers)

Most upvoted comments

/s/shit/ship whoops.

I have the same issue when I use symbolic link that links outside the project (Laravel 5.2), i.e.:

ln -s /var/www/platform/project1/storage/files /var/www/platform/laravel-5.2-project/storage/files

The driver detects that files is not a folder via if ( ! is_dir($root)) { and runs mkdir. The result is the same: mkdir: File exists

Is it possible to include check for symbol links?