From 860590214d7eaedead3c5d64eead979b8fddd2c1 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Mon, 10 Nov 2014 09:27:13 +0000 Subject: [PATCH] Check old version is writeable before update Checks all ICEcoder files are writeable and therefore moveable, before proceeding with the update. If it files any that aren't, it will display a message, list them and die with a link back to ICEcoder. Also ignoring .git dir --- lib/updater.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/updater.php b/lib/updater.php index 8e86c53..b6cebc6 100644 --- a/lib/updater.php +++ b/lib/updater.php @@ -14,6 +14,33 @@ define('PATH', '../tmp/oldVersion/'); $updateDone = false; function startUpdate() { + // First, check old version is entirely moveable + $source = "../"; + $cantMoveArray = array(); + echo 'Checking we can entirely move old ICEcoder version...
'; + foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),RecursiveIteratorIterator::SELF_FIRST) as $item) { + if (strpos($source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(),"oldVersion")==false) { + // Don't move plugins or .git away + $testPath = $source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(); + $testPath = str_replace("\\","/",$testPath); + if (strpos($testPath,"/plugins/")==false && strpos($testPath,"/.git/")==false) { + if (!is_writeable($item)) { + array_push($cantMoveArray,substr($item,count($source)+2)); + } + } + } + } + if (count($cantMoveArray) > 0) { + echo '
Sorry, there are dirs/files that cannot be moved. Please set write permissions on them so ICEcoder may move the old version, to make way for the new.

You can reload this page after making perms changes to check the list again.

'; + for ($i=0; $i"; + } + die('
<< Back to ICEcoder'); + } + renameOldVersion(); +} + +function renameOldVersion() { if (is_dir(PATH)) { echo 'Postfixing oldVersion dir with a timestamp...
'; rename(PATH,trim(PATH,"/")."-".time()); @@ -37,10 +64,10 @@ function copyOldVersion() { echo 'Moving current ICEcoder files...
'; foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),RecursiveIteratorIterator::SELF_FIRST) as $item) { if (strpos($source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(),"oldVersion")==false) { - // Don't move plugins away + // Don't move plugins or .git away $testPath = $source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(); $testPath = str_replace("\\","/",$testPath); - if (strpos($testPath,"/plugins/")==false) { + if (strpos($testPath,"/plugins/")==false && strpos($testPath,"/.git/")==false) { if ($item->isDir()) { mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0755); } else {