Skip to content

Commit 9253214

Browse files
arnegroskurthfabpot
authored andcommitted
[Filesystem] Workaround cannot dumpFile into "protected" folders on Windows
1 parent f0f0665 commit 9253214

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

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
}

Tests/FilesystemTest.php

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

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

0 commit comments

Comments
 (0)