diff --git a/Filesystem.php b/Filesystem.php index 37556e3d8..14a36f6ea 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -233,6 +233,9 @@ public function chmod(string|iterable $files, int $mode, int $umask = 0000, bool /** * Change the owner of an array of files or directories. * + * This method always throws on Windows, as the underlying PHP function is not supported. + * @see https://www.php.net/chown + * * @param string|int $user A user name or number * @param bool $recursive Whether change the owner recursively or not * @@ -261,6 +264,9 @@ public function chown(string|iterable $files, string|int $user, bool $recursive /** * Change the group of an array of files or directories. * + * This method always throws on Windows, as the underlying PHP function is not supported. + * @see https://www.php.net/chgrp + * * @param string|int $group A group name or number * @param bool $recursive Whether change the group recursively or not * @@ -691,6 +697,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); } } diff --git a/Tests/FilesystemTest.php b/Tests/FilesystemTest.php index 4e1d9351a..147ea9b66 100644 --- a/Tests/FilesystemTest.php +++ b/Tests/FilesystemTest.php @@ -1813,6 +1813,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(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy