The temp directory is not prepared in Drupal\Core\File\FileSystem::saveData

Created on 27 November 2020, over 4 years ago
Updated 5 May 2025, 9 days ago

Problem/Motivation

In Drupal\Core\File\FileSystem::saveData,file_put_contents is called without calling prepareDirectory beforehand. In case the temporary directory does not yet exist, this results in the following error when trying to write a temp file:

Temporary file 'temporary://xxxx' could not be created

Steps to reproduce

1. Set $settings['file_temp_path'] to a folder that does not yet exist (eg. a subfolder of /tmp)
2. Somehow trigger Drupal\Core\File\FileSystem::saveData, eg. by clearing cache and visiting the front page with asset aggregation enabled

Proposed resolution

Call prepareDirectory before file_put_contents in Drupal\Core\File\FileSystem::saveData.

Remaining tasks

Write tests.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
File systemΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    As a bug this will need a test case showing the issue.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    liam morland β†’ made their first commit to this issue’s fork.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    I have rebased this on 11.x. The merge request needs to be updated to target 11.x. @DieterHolvoet can you do this?

    How would a test for this be done?

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I changed the target branch.

  • Pipeline finished with Success
    9 days ago
    Total: 1753s
    #489488
  • Pipeline finished with Success
    9 days ago
    Total: 690s
    #489500
  • Pipeline finished with Success
    9 days ago
    Total: 145s
    #489732
  • Pipeline finished with Canceled
    7 days ago
    Total: 72s
    #491771
  • Pipeline finished with Canceled
    7 days ago
    Total: 83s
    #491773
  • Pipeline finished with Failed
    7 days ago
    Total: 132s
    #491774
  • Pipeline finished with Failed
    7 days ago
    Total: 130s
    #491776
  • Pipeline finished with Canceled
    7 days ago
    Total: 90s
    #491777
  • Pipeline finished with Failed
    7 days ago
    Total: 470s
    #491778
  • Pipeline finished with Failed
    7 days ago
    Total: 148s
    #491780
  • Pipeline finished with Success
    7 days ago
    Total: 306s
    #491782
  • Pipeline finished with Success
    7 days ago
    Total: 181s
    #491796
  • Pipeline finished with Success
    7 days ago
    Total: 221s
    #491818
  • Pipeline finished with Success
    1 day ago
    Total: 138s
    #496303
Production build 0.71.5 2024