Skip to content

[Filesystem] Cannot dumpFile into "protected" folders on Windows #39496

Closed
@arnegroskurth

Description

@arnegroskurth

Symfony version(s) affected: 5.2.0

Description

Usage of Symfony\Component\Filesystem\Filesystem::dumpFile failes on Windows when trying to dump e.g. into the personal downloads directory under C:\Users\*\Downloads due to failing of the writeability check for the target folder even though an actual write succeeds.

How to reproduce

<?php

require_once __DIR__ . '/vendor/autoload.php';

$targetFilePath = 'C:/Users/*user*/Downloads/file.ext';

var_dump(is_writable(dirname($targetFilePath))); // bool(false)
var_dump(file_put_contents($targetFilePath, 'foo') !== false); // bool(true)

$filesystem = new Symfony\Component\Filesystem\Filesystem();
$filesystem->dumpFile($targetFilePath, 'bar'); // exception

Possible Solution

Is more of an upstream-problem with PHP's implementation of is_writable (see e.g. https://bugs.php.net/bug.php?id=68926) but it might make sense to just skip the check on Windows to provide a fix within the symfony component.

The root cause is probably the Microsoft Universal Windows Platform app security model.

Additional context

Testing on Windows 10 1904 with

PHP 7.4.12 (cli) (built: Oct 27 2020 17:18:47) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions