Before trying to create public://library-definitions directory in hook_install() it is necessary to check that this directory does not yet exist because \Drupal::service('file_system')->mkdir() won't do it for us.

Otherwise, we can get the following error:

mkdir(): File exists in Drupal\Core\File\FileSystem->mkdirCall() (line 237 of core/lib/Drupal/Core/File/FileSystem.php)

Drupal\Core\File\FileSystem->mkdirCall('/var/www/sites/default/files/library-definitions', 509, , NULL) (Line: 222)
Drupal\Core\File\FileSystem->mkdir('/var/www/sites/default/files/library-definitions', 509, , NULL) (Line: 1159)
drupal_mkdir('/var/www/sites/default/files/library-definitions', 509, ) (Line: 451)
Drupal\Core\StreamWrapper\LocalStream->mkdir('public://library-definitions', 509, 8)
mkdir('public://library-definitions', 509, ) (Line: 237)
Drupal\Core\File\FileSystem->mkdirCall('public://library-definitions', 509, , NULL) (Line: 178)
Drupal\Core\File\FileSystem->mkdir('public://library-definitions') (Line: 16)
libraries_install()
call_user_func_array('libraries_install', Array) (Line: 391)
Drupal\Core\Extension\ModuleHandler->invoke('libraries', 'install') (Line: 287)
Drupal\Core\Extension\ModuleInstaller->install(Array, ) (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array, ) (Line: 1783)
_install_module_batch('libraries', 'Libraries', Array)
call_user_func_array('_install_module_batch', Array) (Line: 252)
_batch_process() (Line: 870)
batch_process(Object, Object) (Line: 617)
install_run_task(Array, Array) (Line: 538)
install_run_tasks(Array) (Line: 115)
install_drupal(Object, Array) (Line: 726)
drush_call_user_func_array('install_drupal', Array) (Line: 711)
drush_op('install_drupal', Object, Array) (Line: 80)
drush_core_site_install_version('tatooine', Array) (Line: 249)
drush_core_site_install('tatooine')
call_user_func_array('drush_core_site_install', Array) (Line: 422)
_drush_invoke_hooks(Array, Array) (Line: 231)
drush_command('tatooine')
call_user_func_array('drush_command', Array) (Line: 199)
drush_dispatch(Array) (Line: 67)
Drush\Boot\BaseBoot->bootstrap_and_dispatch() (Line: 66)
drush_main() (Line: 12)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

20th created an issue. See original summary.

20th’s picture

Status: Active » Needs review
FileSize
1.54 KB

A quick fix is just to check for this directory with is_dir().

Not sure, though, if this patch can be tested because KernelTestBase, which is used as a base class for all tests, does not invoke hook_install() during test setup.

  • 20th authored dcd717d on 8.x-3.x
    Issue #2833756 by 20th: Check that public://library-definitions...
tstoeckler’s picture

Status: Needs review » Fixed

Thank you, that makes total sense!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.