Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2d33fb

Browse files
committed
bug #41893 [Filesystem] Workaround cannot dumpFile into "protected" folders on Windows (arnegroskurth)
This PR was merged into the 4.4 branch. Discussion ---------- [Filesystem] Workaround cannot dumpFile into "protected" folders on Windows | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39496 | License | MIT | Doc PR | Commits ------- 4b9b68c [Filesystem] Workaround cannot dumpFile into "protected" folders on Windows
2 parents 99a8b9f + 4b9b68c commit e2d33fb

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,6 @@ public function dumpFile($filename, $content)
678678
$this->mkdir($dir);
679679
}
680680

681-
if (!is_writable($dir)) {
682-
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
683-
}
684-
685681
// Will create a temp file with 0600 access rights
686682
// when the filesystem supports chmod.
687683
$tmpFile = $this->tempnam($dir, basename($filename));
@@ -721,10 +717,6 @@ public function appendToFile($filename, $content)
721717
$this->mkdir($dir);
722718
}
723719

724-
if (!is_writable($dir)) {
725-
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
726-
}
727-
728720
if (false === @file_put_contents($filename, $content, \FILE_APPEND)) {
729721
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
730722
}

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,27 @@ public function testCopyShouldKeepExecutionPermission()
17561756
$this->assertFilePermissions(767, $targetFilePath);
17571757
}
17581758

1759+
public function testDumpToProtectedDirectory()
1760+
{
1761+
if (\DIRECTORY_SEPARATOR !== '\\') {
1762+
$this->markTestSkipped('This test is specific to Windows.');
1763+
}
1764+
1765+
if (($userProfilePath = getenv('USERPROFILE')) === false || !is_dir($userProfilePath)) {
1766+
throw new \RuntimeException('Failed to retrieve user profile path.');
1767+
}
1768+
1769+
$targetPath = implode(\DIRECTORY_SEPARATOR, [$userProfilePath, 'Downloads', '__test_file.ext']);
1770+
1771+
try {
1772+
$this->assertFileDoesNotExist($targetPath);
1773+
$this->filesystem->dumpFile($targetPath, 'foobar');
1774+
$this->assertFileExists($targetPath);
1775+
} finally {
1776+
$this->filesystem->remove($targetPath);
1777+
}
1778+
}
1779+
17591780
/**
17601781
* Normalize the given path (transform each forward slash into a real directory separator).
17611782
*/

0 commit comments

Comments
 (0)