From 3d2f88e9f5013a5938ed5aad1ee9db2f50ea765f Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 3 Sep 2024 09:46:12 +0200 Subject: [PATCH 1/2] [Filesystem] Add a warning about `chown()` and `chgrp()` on Windows --- Filesystem.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Filesystem.php b/Filesystem.php index 958ef178d..f3761b280 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -233,6 +233,9 @@ public function chmod($files, int $mode, int $umask = 0000, bool $recursive = fa /** * 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|iterable $files A filename, an array of files, or a \Traversable instance to change owner * @param string|int $user A user name or number * @param bool $recursive Whether change the owner recursively or not @@ -260,6 +263,9 @@ public function chown($files, $user, bool $recursive = false) /** * 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|iterable $files A filename, an array of files, or a \Traversable instance to change group * @param string|int $group A group name or number * @param bool $recursive Whether change the group recursively or not From 71fefa2ca8efbc211e36967b359eb52c0b30a648 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 5 Sep 2024 14:18:51 +0200 Subject: [PATCH 2/2] make sure temp files can be cleaned up on Windows --- Filesystem.php | 4 ++++ Tests/FilesystemTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Filesystem.php b/Filesystem.php index 958ef178d..3efd5f6d5 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -696,6 +696,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 eea5fe1a6..d1722db93 100644 --- a/Tests/FilesystemTest.php +++ b/Tests/FilesystemTest.php @@ -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(); 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