Escape file name with slash

Created on 15 February 2024, 9 months ago
Updated 5 September 2024, 2 months ago

Problem/Motivation

When using module views_data_export to export data and setting the view to use "batches" instead of generating the whole report, it cannot create all the required subdirectories as FileSystem:prepareDestination does pass a parameter to prepareDirectory which allows it to create the subdirectories. Instead it raises an exception:

The specified file 'temporary://xxxx' could not be copied because the destination directory 'private://path/path2/path3' is not properly configured. This may be caused by a problem with file or directory permissions.

Steps to reproduce

- Install module views_data_export
- create any content
- setup a view of that content using an export (csv type), then set the 'export settings' method to batch instead of general
- open your view and see the error.

Proposed resolution

i'm generating a patch and will link to this issue

✨ Feature request
Status

Active

Version

1.0

Component
File systemΒ  β†’

Last updated 2 days ago

Created by

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

Comments & Activities

  • Issue created by @jez300
  • Status changed to Postponed: needs info 9 months ago
  • Drupal 9 is end-of-life and is not accepting bug reports. Please test for the bug on a supported release.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Should this issue be against views data export

    The module writing the files is responsible for creating the folders

  • Status changed to Active 9 months ago
  • That was quick. Thank you for the replies.

    larowlan: Thanks for suggesting a fix might be needed in Views data export. That module brought to light the problem creating subdirs, but the fix needed to be in Drupal core.

    cilefen: Druapl 9 at end of life: Thanks. I built a patch for my drupal 9 version and will share. I also checked Drupal 10, the issues is still there, I would like to suggest adding a fix to one line in the core which is:

    web/core/lib/Drupal/Core/File/FileSystem.php in function prepareDestination

    Instead of calling prepareDirectory with 1 parameter, it should have 2, just like it's used in many other places from within Drupal, like this:

    $this->prepareDirectory($dirname, self::CREATE_DIRECTORY | self::MODIFY_PERMISSIONS)

    or at least like this:

    $this->prepareDirectory($dirname, self::CREATE_DIRECTORY)

    Thanks

  • That function doesn’t say it creates directories in its documentation.

  • πŸ‡¨πŸ‡΄Colombia JsonJimenez

    Patch updated for version 10.2.3

  • πŸ‡¨πŸ‡³China skyredwang Shanghai

    I ran into the problem, and looked into the code.

    Drupal Core has no problem. views_data_export module also correctly prepared the folder with subfolders on this line

    $fileSystem = \Drupal::service('file_system');
    $fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
    $destination = $directory . $filename;
    

    The actual problem, at least in my case, was that my filename contains a date, which contains the slash /, which tricks Drupal core to think there are more subfolders.

    I repurposed this issue that for this module, it can escape the slash in the filename, which can help users to get around this problem.

Production build 0.71.5 2024