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, about 1 month 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 2 days 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
    about 1 month ago
    Total: 1753s
    #489488
  • Pipeline finished with Success
    about 1 month ago
    Total: 690s
    #489500
  • Pipeline finished with Success
    about 1 month ago
    Total: 145s
    #489732
  • Pipeline finished with Canceled
    29 days ago
    Total: 72s
    #491771
  • Pipeline finished with Canceled
    29 days ago
    Total: 83s
    #491773
  • Pipeline finished with Failed
    29 days ago
    Total: 132s
    #491774
  • Pipeline finished with Failed
    29 days ago
    Total: 130s
    #491776
  • Pipeline finished with Canceled
    29 days ago
    Total: 90s
    #491777
  • Pipeline finished with Failed
    29 days ago
    Total: 470s
    #491778
  • Pipeline finished with Failed
    29 days ago
    Total: 148s
    #491780
  • Pipeline finished with Success
    29 days ago
    Total: 306s
    #491782
  • Pipeline finished with Success
    29 days ago
    Total: 181s
    #491796
  • Pipeline finished with Success
    29 days ago
    Total: 221s
    #491818
  • Pipeline finished with Success
    23 days ago
    Total: 138s
    #496303
  • Pipeline finished with Failed
    22 days ago
    Total: 242s
    #497704
  • Pipeline finished with Failed
    16 days ago
    Total: 180s
    #502013
  • Pipeline finished with Success
    16 days ago
    Total: 228s
    #502025
  • Pipeline finished with Failed
    16 days ago
    Total: 230s
    #502058
  • Pipeline finished with Failed
    16 days ago
    Total: 194s
    #502368
  • Pipeline finished with Success
    16 days ago
    Total: 374s
    #502424
  • Pipeline finished with Success
    15 days ago
    Total: 260s
    #502723
  • Pipeline finished with Failed
    15 days ago
    #502775
  • Pipeline finished with Success
    15 days ago
    Total: 242s
    #502779
  • Pipeline finished with Success
    15 days ago
    Total: 241s
    #502790
  • Pipeline finished with Failed
    15 days ago
    Total: 194s
    #503036
  • Pipeline finished with Failed
    15 days ago
    Total: 191s
    #503049
  • Pipeline finished with Success
    8 days ago
    Total: 221s
    #508349
  • Pipeline finished with Success
    2 days ago
    Total: 246s
    #513148
Production build 0.71.5 2024