Skip to content

Commit

Permalink
Fix MaxMind MMDB extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Jun 20, 2024
1 parent 3b4a722 commit 2919b22
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 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,11 +42,16 @@ public function update(Command $command): void
$this->getDatabaseUrl()
);

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

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

$relativePath = implode('/', [
Str::afterLast($file->getPath(), DIRECTORY_SEPARATOR),
$file->getFilename(),
]);

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

file_put_contents(
$this->getDatabasePath(),
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

0 comments on commit 2919b22

Please sign in to comment.