From b0d46dc4a3b831c852f10ccb6082f43bc9bda033 Mon Sep 17 00:00:00 2001
From: Richard Mastop <RMastop@users.noreply.github.com>
Date: Mon, 18 Sep 2017 05:36:56 +0200
Subject: [PATCH] copy file instead of renaming it. (#11908)

* copy file instead of renaming it.

As stated in thread; fixes #5050

* Update GeoIPAutoUpdater.php

In most cases the rename is successful, in rare cases the rename cannot be completed. In those cases we do a copy, leaving the $tempFile in place, it will be overwritten during the next  GeoIPAutopudater task.

Tested in both windows and Ubuntu environment.

* Add unlink
---
 plugins/UserCountry/GeoIPAutoUpdater.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/plugins/UserCountry/GeoIPAutoUpdater.php b/plugins/UserCountry/GeoIPAutoUpdater.php
index 77636afdd1..2c44ebb66d 100755
--- a/plugins/UserCountry/GeoIPAutoUpdater.php
+++ b/plugins/UserCountry/GeoIPAutoUpdater.php
@@ -268,7 +268,11 @@ class GeoIPAutoUpdater extends Task
             }
 
             $tempFile = GeoIp::getPathForGeoIpDatabase($tempFilename);
-            rename($tempFile, $oldDbFile);
+            if (@rename($tempFile, $oldDbFile) !== true) {
+                //In case the $tempfile cannot be renamed, we copy the file.
+                copy($tempFile, $oldDbFile);
+                unlink($tempFile);
+            }
 
             // delete original archive
             if ($unlink) {
-- 
GitLab