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

ZipArchiveAdapter changes for dealing with root dir ('') #1548

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions src/ZipArchive/ZipArchiveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

use function fclose;
use function fopen;
use function is_file;
use function rewind;
use function stream_copy_to_stream;
use function unlink;

final class ZipArchiveAdapter implements FilesystemAdapter
{
Expand Down Expand Up @@ -173,7 +175,13 @@ public function deleteDirectory(string $path): void

$archive->deleteName($prefixedPath);

$filename = $archive->filename;

$archive->close();

if ('' === $path) {
unlink($filename);
}
}

public function createDirectory(string $path, Config $config): void
Expand All @@ -190,6 +198,10 @@ public function directoryExists(string $path): bool
$archive = $this->zipArchiveProvider->createZipArchive();
$location = $this->pathPrefixer->prefixDirectoryPath($path);

if ('' === $path) {
return is_file($archive->filename);
}

return $archive->statName($location) !== false;
}

Expand Down
29 changes: 29 additions & 0 deletions src/ZipArchive/ZipArchiveAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,35 @@ public function failing_to_set_visibility_because_setting_it_fails(): void
$this->adapter()->setVisibility('path.txt', Visibility::PUBLIC);
}

/**
* @test
*/
public function checking_if_root_exists_checks_if_file_exists(): void
{
$adapter = $this->adapter();

$this->assertFalse($adapter->directoryExists(''));

$adapter->write('foo.txt', 'content', new Config());

$this->assertTrue($adapter->directoryExists(''));
}

/**
* @test
*/
public function deleting_root_deletes_file(): void
{
$adapter = $this->adapter();
$adapter->write('foo.txt', 'content', new Config());

$this->assertFileExists(self::ARCHIVE);

$adapter->deleteDirectory('');

$this->assertFileDoesNotExist(self::ARCHIVE);
}

protected static function removeZipArchive(): void
{
if ( ! file_exists(self::ARCHIVE)) {
Expand Down