Directory "private:" is created if file_private_path is not set

Created on 29 August 2019, almost 5 years ago
Updated 25 January 2023, over 1 year ago

Context
A module using a file field with private File enabled is activated, but $settings['file_private_path'] is NOT defined.

Using UI to create a new node will create a validation Error "The file could not be uploaded." which is minimalistic as it doesn't tell the reason, but acceptable.

Problem

If you programmatically create nodes e.g using devel-generate, there will be a directory created in web root with the name "private:".

Even though there are 'Unable to find the wrapper "private"' warnings the following code will create a directory

if ($options & static::CREATE_DIRECTORY) {
        return @$this->mkdir($directory, NULL, TRUE);
}

web/core/lib/Drupal/Core/File/FileSystem.php#L51-53

The Directory must not be created if there is no private stream wrapper and there should be a Error message which tells you that you need to configure private files.

[warning] is_dir(): Unable to find the wrapper "private" - did you forget to enable it when you configured PHP? FileSystem.php:548
[warning] is_dir(): Unable to find the wrapper "private" - did you forget to enable it when you configured PHP? FileSystem.php:548
[warning] is_writable(): Unable to find the wrapper "private" - did you forget to enable it when you configured PHP? FileSystem.php:557
[notice] The data could not be saved because the destination private://2019-08/yeAv0PfETJ.txt is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.

Related: Files prepareDestination Exception improvement
https://www.drupal.org/project/drupal/issues/3070902 β†’

For reference the full error message:
Using attached ctype and a Drupal release 8.7.6

drush devel-generate-content --types content_with_private_field
 [warning] is_dir(): Unable to find the wrapper "private" - did you forget to enable it when you configured PHP? FileSystem.php:548
 [warning] is_dir(): Unable to find the wrapper "private" - did you forget to enable it when you configured PHP? FileSystem.php:548
 [warning] is_writable(): Unable to find the wrapper "private" - did you forget to enable it when you configured PHP? FileSystem.php:557
 [notice] The data could not be saved because the destination private://2019-08/yeAv0PfETJ.txt is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.
 [error]  Error: Call to a member function id() on boolean in Drupal\file\Plugin\Field\FieldType\FileItem::generateSampleValue() (line 337 of /Users/tho/htdocs/GzEvD/DEGOV-579/web/core/modules/file/src/Plugin/Field/FieldType/FileItem.php) #0 /Users/tho/htdocs/GzEvD/DEGOV-579/web/core/lib/Drupal/Core/Field/FieldItemList.php(253): Drupal\file\Plugin\Field\FieldType\FileItem::generateSampleValue(Object(Drupal\field\Entity\FieldConfig))
#1 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/DevelGenerateBase.php(116): Drupal\Core\Field\FieldItemList->generateSampleItems(1)
#2 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php(517): Drupal\devel_generate\DevelGenerateBase::populateFields(Object(Drupal\node\Entity\Node))
#3 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php(340): Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate->develGenerateContentAddNode(Array)
#4 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php(318): Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate->generateContent(Array)
#5 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/DevelGenerateBase.php(75): Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate->generateElements(Array)
#6 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(188): Drupal\devel_generate\DevelGenerateBase->generate(Array)
#7 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(166): Drupal\devel_generate\Commands\DevelGenerateCommands->generate()
#8 [internal function]: Drupal\devel_generate\Commands\DevelGenerateCommands->content(50, 0, Array)
#9 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#10 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#11 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#12 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#13 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Application.php(981): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Application.php(254): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Application.php(147): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#20 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/includes/preflight.inc(18): require('/Users/tho/htdo...')
#21 phar:///opt/local/drush/drush-launcher.phar/bin/drush.php(141): drush_main()
#22 /opt/local/drush/drush-launcher.phar(10): require('phar:///opt/loc...')
#23 {main}.
Error: Call to a member function id() on boolean in /Users/tho/htdocs/GzEvD/DEGOV-579/web/core/modules/file/src/Plugin/Field/FieldType/FileItem.php on line 337 #0 /Users/tho/htdocs/GzEvD/DEGOV-579/web/core/lib/Drupal/Core/Field/FieldItemList.php(253): Drupal\file\Plugin\Field\FieldType\FileItem::generateSampleValue(Object(Drupal\field\Entity\FieldConfig))
#1 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/DevelGenerateBase.php(116): Drupal\Core\Field\FieldItemList->generateSampleItems(1)
#2 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php(517): Drupal\devel_generate\DevelGenerateBase::populateFields(Object(Drupal\node\Entity\Node))
#3 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php(340): Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate->develGenerateContentAddNode(Array)
#4 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php(318): Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate->generateContent(Array)
#5 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/DevelGenerateBase.php(75): Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate->generateElements(Array)
#6 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(188): Drupal\devel_generate\DevelGenerateBase->generate(Array)
#7 /Users/tho/htdocs/GzEvD/DEGOV-579/web/modules/contrib/devel/devel_generate/src/Commands/DevelGenerateCommands.php(166): Drupal\devel_generate\Commands\DevelGenerateCommands->generate()
#8 [internal function]: Drupal\devel_generate\Commands\DevelGenerateCommands->content(50, 0, Array)
#9 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#10 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#11 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#12 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#13 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Application.php(981): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Application.php(254): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/symfony/console/Application.php(147): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#20 /Users/tho/htdocs/GzEvD/DEGOV-579/vendor/drush/drush/includes/preflight.inc(18): require('/Users/tho/htdo...')
#21 phar:///opt/local/drush/drush-launcher.phar/bin/drush.php(141): drush_main()
#22 /opt/local/drush/drush-launcher.phar(10): require('phar:///opt/loc...')
#23 {main}
Error: Call to a member function id() on boolean in Drupal\file\Plugin\Field\FieldType\FileItem::generateSampleValue() (line 337 of /Users/tho/htdocs/GzEvD/DEGOV-579/web/core/modules/file/src/Plugin/Field/FieldType/FileItem.php).
 [warning] Drush command terminated abnormally. Check for an exit() in your Drupal site.
πŸ› Bug report
Status

Active

Version

10.1 ✨

Component
File systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡©πŸ‡ͺGermany digitaldonkey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
Production build 0.69.0 2024