Skip to content

Commit

Permalink
Merge pull request #178 from stevebauman/BUG-177
Browse files Browse the repository at this point in the history
Bug 177 - An error PharException occurred when trying to update files maxmind
  • Loading branch information
stevebauman authored Jun 20, 2024
2 parents 3033fc6 + 5a56cc5 commit f565e2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/Drivers/MaxMind.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Support\Str;
use PharData;
use PharFileInfo;
use RecursiveIteratorIterator;
use Stevebauman\Location\Position;
use Stevebauman\Location\Request;

Expand Down Expand Up @@ -41,18 +42,23 @@ public function update(Command $command): void
$this->getDatabaseUrl()
);

$file = $this->discoverDatabaseFile(
$archive = new PharData($tarFilePath)
);
$archive = new PharData($tarFilePath);

$file = $this->discoverDatabaseFile($archive);

$directory = Str::afterLast($file->getPath(), DIRECTORY_SEPARATOR);

$archive->extractTo($storage->path('/'), $file->getFilename(), true);
$relativePath = implode('/', [$directory, $file->getFilename()]);

$archive->extractTo($storage->path('/'), $relativePath, true);

file_put_contents(
$this->getDatabasePath(),
fopen($storage->path($file->getFilename()), 'r')
fopen($storage->path($relativePath), 'r')
);

$storage->delete($tarFileName);
$storage->deleteDirectory($directory);
}

/**
Expand All @@ -62,14 +68,7 @@ public function update(Command $command): void
*/
protected function discoverDatabaseFile(PharData $archive): PharFileInfo
{
/** @var \FilesystemIterator $file */
foreach ($archive as $file) {
if ($file->isDir()) {
return $this->discoverDatabaseFile(
new PharData($file->getPathName())
);
}

foreach (new RecursiveIteratorIterator($archive) as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'mmdb') {
return $file;
}
Expand Down
Binary file modified tests/fixtures/maxmind.tar.gz
Binary file not shown.

0 comments on commit f565e2b

Please sign in to comment.