From b7b92bcc576e4d6678bac45bf1bd564ba98a7ce2 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 8 Nov 2021 09:01:15 +0100 Subject: [PATCH] replace rename() by exec('mv ..') --- inc/inc.ClassExtensionMgr.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/inc/inc.ClassExtensionMgr.php b/inc/inc.ClassExtensionMgr.php index dac9c8a9a..b70f0fe3b 100644 --- a/inc/inc.ClassExtensionMgr.php +++ b/inc/inc.ClassExtensionMgr.php @@ -488,7 +488,7 @@ class SeedDMS_Extension_Mgr { */ public function updateExtension($file) { /* {{{ */ /* unzip the extension in a temporary directory */ - $newdir = $this->cachedir ."/ext.new"; + $newdir = addDirSep($this->cachedir)."ext.new"; /* First remove a left over from a previous extension */ if(file_exists($newdir)) { self::rrmdir($newdir); @@ -529,7 +529,21 @@ class SeedDMS_Extension_Mgr { $this->rrmdir($this->extdir ."/". $extname); } /* Move the temp. created ext directory to the final location */ - if(!rename($newdir, $this->extdir ."/". $extname)) { + /* rename() may fail if dirs are moved from one device to another. + * See https://bugs.php.net/bug.php?id=54097 + * + * exec("mv ".escapeshellarg($newdir)." ".escapeshellarg($this->extdir ."/". $extname)); + * + * It's also sufficient to just copy the extracted archive to the final + * location and leave the extracted archive in place. The next time an + * extension is imported the last extracted archive will be removed. + */ +// if(!rename($newdir, $this->extdir ."/". $extname)) { + if(false === exec('mv '.escapeshellarg($newdir).' '.escapeshellarg($this->extdir."/".$extname))) { + /* If copy didn't succeed, then there is probably nothing to delete, + * but do it anyway, just to be sure not just parts of the extension + * has been copied. + */ $this->rrmdir($this->extdir ."/". $extname); return false; }