Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2020-12-10 13:20:20 +0300
committerGitHub <noreply@github.com>2020-12-10 13:20:20 +0300
commitcd0e0fef1d67e0448fc57e146a2dc3af1b1ce24b (patch)
treed54e7fc3c83c520ac39448cb4b1ea9bf300bcf86 /plugins/GeoIp2
parent2d430ba92315f5ce7e93989da8de4bd9b95916b4 (diff)
Append a suffix to temporary downloaded geoip files (#16704)
Diffstat (limited to 'plugins/GeoIp2')
-rw-r--r--plugins/GeoIp2/Controller.php4
-rw-r--r--plugins/GeoIp2/GeoIP2AutoUpdater.php23
2 files changed, 17 insertions, 10 deletions
diff --git a/plugins/GeoIp2/Controller.php b/plugins/GeoIp2/Controller.php
index 17b451eb19..5a3c88b2c1 100644
--- a/plugins/GeoIp2/Controller.php
+++ b/plugins/GeoIp2/Controller.php
@@ -36,7 +36,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
- $outputPath = GeoIP2AutoUpdater::getTemporaryFolder('DBIP-City.mmdb') . '.gz';
+ $outputPath = GeoIP2AutoUpdater::getTemporaryFolder('DBIP-City.mmdb.gz', true);
try {
$result = Http::downloadChunk(
$url = GeoIp2::getDbIpLiteUrl(),
@@ -146,7 +146,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
$url = GeoIP2AutoUpdater::getConfiguredUrl($key);
$filename = GeoIP2AutoUpdater::getZippedFilenameToDownloadTo($url, $key, GeoIP2AutoUpdater::getGeoIPUrlExtension($url));
- $outputPath = GeoIP2AutoUpdater::getTemporaryFolder($filename);
+ $outputPath = GeoIP2AutoUpdater::getTemporaryFolder($filename, true);
// download part of the file
$result = Http::downloadChunk(
diff --git a/plugins/GeoIp2/GeoIP2AutoUpdater.php b/plugins/GeoIp2/GeoIP2AutoUpdater.php
index 7d64dc9e9a..d144c66b5b 100644
--- a/plugins/GeoIp2/GeoIP2AutoUpdater.php
+++ b/plugins/GeoIp2/GeoIP2AutoUpdater.php
@@ -158,7 +158,7 @@ class GeoIP2AutoUpdater extends Task
// NOTE: using the first item in $dbNames[$dbType] makes sure GeoLiteCity will be renamed to GeoIPCity
$zippedFilename = $this->getZippedFilenameToDownloadTo($url, $dbType, $ext);
- $zippedOutputPath = self::getTemporaryFolder($zippedFilename);
+ $zippedOutputPath = self::getTemporaryFolder($zippedFilename, true);
$url = self::removeDateFromUrl($url);
@@ -192,9 +192,9 @@ class GeoIP2AutoUpdater extends Task
Log::info("GeoIP2AutoUpdater: successfully updated GeoIP 2 database '%s'", $url);
}
- public static function getTemporaryFolder($file)
+ public static function getTemporaryFolder($file, $isDownload = false)
{
- return \Piwik\Container\StaticContainer::get('path.tmp') . '/latest/' . $file;
+ return \Piwik\Container\StaticContainer::get('path.tmp') . '/latest/' . $file . ($isDownload ? '.download' : '');
}
/**
@@ -207,10 +207,17 @@ class GeoIP2AutoUpdater extends Task
public static function unzipDownloadedFile($path, $dbType, $url, $unlink = false)
{
$isDbIp = self::isDbIpUrl($url);
- $isDbIpUnknownDbType = $isDbIp && substr($path, -5, 5) == '.mmdb';
+
+ $filename = $path;
+
+ if (substr($filename, -9, 9) === '.download') {
+ $filename = substr($filename, 0, -9);
+ }
+
+ $isDbIpUnknownDbType = $isDbIp && substr($filename, -5, 5) == '.mmdb';
// extract file
- if (substr($path, -7, 7) == '.tar.gz') {
+ if (substr($filename, -7, 7) == '.tar.gz') {
// find the .dat file in the tar archive
$unzip = Unzip::factory('tar.gz', $path);
$content = $unzip->listContent();
@@ -253,7 +260,7 @@ class GeoIP2AutoUpdater extends Task
$fd = fopen($outputPath, 'wb');
fwrite($fd, $unzipped);
fclose($fd);
- } else if (substr($path, -3, 3) == '.gz'
+ } else if (substr($filename, -3, 3) == '.gz'
|| $isDbIpUnknownDbType
) {
$unzip = Unzip::factory('gz', $path);
@@ -261,7 +268,7 @@ class GeoIP2AutoUpdater extends Task
if ($isDbIpUnknownDbType) {
$tempFilename = 'unzipped-temp-dbip-file.mmdb';
} else {
- $dbFilename = substr(basename($path), 0, -3);
+ $dbFilename = substr(basename($filename), 0, -3);
$tempFilename = $dbFilename . '.new';
}
@@ -278,7 +285,7 @@ class GeoIP2AutoUpdater extends Task
$dbFilename = $php->detectDatabaseType($dbType) . '.mmdb';
}
} else {
- $parts = explode(basename($path), '.', 2);
+ $parts = explode(basename($filename), '.', 2);
$ext = end($parts);
throw new Exception(Piwik::translate('GeoIp2_UnsupportedArchiveType', "'$ext'"));
}