Skip to content

Commit

Permalink
Merge pull request #1723 from jnoordsij/local-adapter-use-visibility
Browse files Browse the repository at this point in the history
Use visibility on copy/move operations in local adapter
  • Loading branch information
frankdejonge authored Nov 6, 2023
2 parents 702e2b4 + b7e7966 commit 593da2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit 593da2e

Please sign in to comment.