From be0b4e1710bdf8941bdb1c387058878d4e05828a Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Mon, 19 Jun 2017 10:44:04 +0300 Subject: [PATCH] uncompress downloaded database to tmp file and fast cope it to target file --- src/Command/UpdateDatabaseCommand.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Command/UpdateDatabaseCommand.php b/src/Command/UpdateDatabaseCommand.php index c0e2891..ba3f295 100644 --- a/src/Command/UpdateDatabaseCommand.php +++ b/src/Command/UpdateDatabaseCommand.php @@ -99,20 +99,25 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->title('Update the GeoIP2 database'); $this->stopwatch->start('update'); - $tmp = sys_get_temp_dir().DIRECTORY_SEPARATOR.basename($target); + $tmp_zip = sys_get_temp_dir().DIRECTORY_SEPARATOR.basename(parse_url($url, PHP_URL_PATH)); + $tmp_unzip = sys_get_temp_dir().DIRECTORY_SEPARATOR. basename($target); $io->comment(sprintf('Beginning download of file: %s', $url)); - file_put_contents($tmp, fopen($url, 'rb')); + file_put_contents($tmp_zip, fopen($url, 'rb')); $io->comment('Download complete'); $io->comment('De-compressing file'); $this->fs->mkdir(dirname($target), 0777); - $this->compressor->uncompress($tmp, $target); - $this->fs->chmod($target, 0777); + $this->compressor->uncompress($tmp_zip, $tmp_unzip); $io->comment('Decompression complete'); + + $this->fs->copy($tmp_unzip, $target, true); + $this->fs->chmod($target, 0777); + $this->fs->remove([$tmp_zip, $tmp_unzip]); + $io->success('Finished downloading'); $this->stopwatch($io, $this->stopwatch->stop('update'));