From e8d9d7ac123c58275f2a7144dfd836ad3fcf9227 Mon Sep 17 00:00:00 2001 From: ChS Date: Wed, 1 Mar 2017 19:26:18 +0100 Subject: [PATCH 1/3] dumpFile(), preserve existing file permissions When calling Filesystem::dumpFile() on an already existing file, its permissions are lost. --- src/Symfony/Component/Filesystem/Filesystem.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index a1ff41e892b70..7261473bb3131 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -516,7 +516,14 @@ public function dumpFile($filename, $content, $mode = 0666) } $this->chmod($tmpFile, $mode); + } else { + if (file_exists($filename)) { + @chmod($tmpFile, fileperms($filename)); + } else { + @chmod($tmpFile, 0666 & ~umask()); + } } + $this->rename($tmpFile, $filename, true); } From 052947b96aaee9ffd02a89ab246892ad18fbbbcd Mon Sep 17 00:00:00 2001 From: ChS Date: Wed, 1 Mar 2017 19:29:47 +0100 Subject: [PATCH 2/3] fix CS --- src/Symfony/Component/Filesystem/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 7261473bb3131..2d9adb8b6a2b0 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -523,7 +523,7 @@ public function dumpFile($filename, $content, $mode = 0666) @chmod($tmpFile, 0666 & ~umask()); } } - + $this->rename($tmpFile, $filename, true); } From 076a225bcc51a348b4f1e54a2a4c83911a07347d Mon Sep 17 00:00:00 2001 From: ChS Date: Mon, 6 Mar 2017 13:46:40 +0100 Subject: [PATCH 3/3] ternary op and positive condition --- src/Symfony/Component/Filesystem/Filesystem.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 2d9adb8b6a2b0..16d83dc2e5fea 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -517,11 +517,7 @@ public function dumpFile($filename, $content, $mode = 0666) $this->chmod($tmpFile, $mode); } else { - if (file_exists($filename)) { - @chmod($tmpFile, fileperms($filename)); - } else { - @chmod($tmpFile, 0666 & ~umask()); - } + @chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask()); } $this->rename($tmpFile, $filename, true);