From f5da50373a07bd2678d6af5ebd6d8e8407468f1a Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 18 Nov 2023 14:41:24 +0100 Subject: [PATCH 1/2] Retain visibility on copying files with LocalAdapter by default --- src/Local/LocalFilesystemAdapter.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index d0e8e743d..9edc39f6e 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -270,7 +270,14 @@ public function copy(string $source, string $destination, Config $config): void throw UnableToCopyFile::because(error_get_last()['message'] ?? 'unknown', $source, $destination); } - if ($visibility = $config->get(Config::OPTION_VISIBILITY)) { + $visibility = $config->get( + Config::OPTION_VISIBILITY, + $config->get('retain_visibility', true) + ? $this->visibility($source)->visibility() + : null, + ); + + if ($visibility) { $this->setVisibility($destination, (string) $visibility); } } From a14e97b3d773da7757ac114da82948444531850a Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 18 Nov 2023 14:41:42 +0100 Subject: [PATCH 2/2] Add test for retaining visibility on LocalAdapter --- src/Local/LocalFilesystemAdapterTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Local/LocalFilesystemAdapterTest.php b/src/Local/LocalFilesystemAdapterTest.php index 84697d883..39562f6f3 100644 --- a/src/Local/LocalFilesystemAdapterTest.php +++ b/src/Local/LocalFilesystemAdapterTest.php @@ -589,6 +589,23 @@ public function copying_a_file_with_visibility(): void $this->assertFileHasPermissions(static::ROOT . '/second.txt', 0600); } + /** + * @test + */ + public function copying_a_file_retaining_visibility(): void + { + $adapter = new LocalFilesystemAdapter(static::ROOT, new PortableVisibilityConverter()); + $adapter->write('first.txt', 'contents', new Config(['visibility' => 'private'])); + $adapter->copy('first.txt', 'retain.txt', new Config()); + $adapter->copy('first.txt', 'do-not-retain.txt', new Config(['retain_visibility' => false])); + $this->assertFileExists(static::ROOT . '/first.txt'); + $this->assertFileHasPermissions(static::ROOT . '/first.txt', 0600); + $this->assertFileExists(static::ROOT . '/retain.txt'); + $this->assertFileHasPermissions(static::ROOT . '/retain.txt', 0600); + $this->assertFileExists(static::ROOT . '/do-not-retain.txt'); + $this->assertFileHasPermissions(static::ROOT . '/do-not-retain.txt', 0644); + } + /** * @test */