Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use visibility on copy/move operations in local adapter #1723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/Local/LocalFilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
Loading