From 0be2154fea0091abc6e446a8d55b50515b1be18e Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Fri, 3 Nov 2023 21:09:34 +0100 Subject: [PATCH 1/2] Set visibility on copy and move methods in LocalFilesystemAdapter --- src/Local/LocalFilesystemAdapter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index c91a9bfa5..60b898554 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -250,6 +250,10 @@ public function move(string $source, string $destination, Config $config): void if ( ! @rename($sourcePath, $destinationPath)) { throw UnableToMoveFile::because(error_get_last()['message'] ?? 'unknown reason', $source, $destination); } + + if ($visibility = $config->get(Config::OPTION_VISIBILITY)) { + $this->setVisibility($destination, (string) $visibility); + } } public function copy(string $source, string $destination, Config $config): void @@ -265,6 +269,10 @@ public function copy(string $source, string $destination, Config $config): void if ( ! @copy($sourcePath, $destinationPath)) { throw UnableToCopyFile::because(error_get_last()['message'] ?? 'unknown', $source, $destination); } + + if ($visibility = $config->get(Config::OPTION_VISIBILITY)) { + $this->setVisibility($destination, (string) $visibility); + } } public function read(string $path): string From b7e7966aa55f608116267fa295cada0dc99ffc39 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Fri, 3 Nov 2023 21:17:21 +0100 Subject: [PATCH 2/2] Add tests for copying and moving files with visibility specifier --- src/Local/LocalFilesystemAdapterTest.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Local/LocalFilesystemAdapterTest.php b/src/Local/LocalFilesystemAdapterTest.php index 8cb26ac92..b17e32d26 100644 --- a/src/Local/LocalFilesystemAdapterTest.php +++ b/src/Local/LocalFilesystemAdapterTest.php @@ -536,6 +536,20 @@ public function moving_a_file(): void $this->assertFileDoesNotExist(static::ROOT . '/first.txt'); } + /** + * @test + */ + public function moving_a_file_with_visibility(): void + { + $adapter = new LocalFilesystemAdapter(static::ROOT, new PortableVisibilityConverter()); + $adapter->write('first.txt', 'contents', new Config()); + $this->assertFileExists(static::ROOT . '/first.txt'); + $this->assertFileHasPermissions(static::ROOT . '/first.txt', 0644); + $adapter->move('first.txt', 'second.txt', new Config(['visibility' => 'private'])); + $this->assertFileExists(static::ROOT . '/second.txt'); + $this->assertFileHasPermissions(static::ROOT . '/second.txt', 0600); + } + /** * @test */ @@ -558,6 +572,20 @@ public function copying_a_file(): void $this->assertFileExists(static::ROOT . '/first.txt'); } + /** + * @test + */ + public function copying_a_file_with_visibility(): void + { + $adapter = new LocalFilesystemAdapter(static::ROOT, new PortableVisibilityConverter()); + $adapter->write('first.txt', 'contents', new Config()); + $adapter->copy('first.txt', 'second.txt', new Config(['visibility' => 'private'])); + $this->assertFileExists(static::ROOT . '/first.txt'); + $this->assertFileHasPermissions(static::ROOT . '/first.txt', 0644); + $this->assertFileExists(static::ROOT . '/second.txt'); + $this->assertFileHasPermissions(static::ROOT . '/second.txt', 0600); + } + /** * @test */