Skip to content

Commit

Permalink
Merge pull request #1730 from jnoordsij/local-adapter-retain-visibility
Browse files Browse the repository at this point in the history
Retain file visibility when copying in LocalAdapter
  • Loading branch information
frankdejonge authored Nov 18, 2023
2 parents fc4a826 + a14e97b commit 3072f52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/Local/LocalFilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 3072f52

Please sign in to comment.