Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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)
Comment | File | Size | Author |
---|---|---|---|
#2 | libraries-1054616-2.patch | 1.54 KB | 20th |
|
Comments
Comment #2
20th CreditAttribution: 20th commentedA 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 invokehook_install()
during test setup.Comment #4
tstoecklerThank you, that makes total sense!