Skip to content

Commit

Permalink
bug #58185 [Filesystem] make sure temp files can be cleaned up on Win…
Browse files Browse the repository at this point in the history
…dows (xabbuh)

This PR was merged into the 5.4 branch.

Discussion
----------

[Filesystem] make sure temp files can be cleaned up on Windows

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

based on the findings while debugging the AppVeyor failures that we worked around in #58152

Commits
-------

a832b672ce make sure temp files can be cleaned up on Windows
  • Loading branch information
nicolas-grekas committed Sep 16, 2024
2 parents 3d2f88e + 71fefa2 commit 76c3818
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ public function dumpFile(string $filename, $content)
$this->rename($tmpFile, $filename, true);
} finally {
if (file_exists($tmpFile)) {
if ('\\' === \DIRECTORY_SEPARATOR && !is_writable($tmpFile)) {
self::box('chmod', $tmpFile, self::box('fileperms', $tmpFile) | 0200);
}

self::box('unlink', $tmpFile);
}
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,22 @@ public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
$this->assertFilePermissions(745, $filename);
}

public function testDumpFileCleansUpAfterFailure()
{
$targetFile = $this->workspace.'/dump-file';
$this->filesystem->touch($targetFile);
$this->filesystem->chmod($targetFile, 0444);

try {
$this->filesystem->dumpFile($targetFile, 'any content');
} catch (IOException $e) {
} finally {
$this->filesystem->chmod($targetFile, 0666);
}

$this->assertSame([$targetFile], glob($this->workspace.'/*'));
}

public function testCopyShouldKeepExecutionPermission()
{
$this->markAsSkippedIfChmodIsMissing();
Expand Down

0 comments on commit 76c3818

Please sign in to comment.