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 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 */