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
This commit is contained in:
Matt Pass
2014-11-10 09:27:13 +00:00
parent 1d69fabce2
commit 860590214d

View File

@@ -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...<br>';
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 '<br>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.<br><br>You can reload this page after making perms changes to check the list again.<br><br>';
for ($i=0; $i<count($cantMoveArray); $i++) {
echo $cantMoveArray[$i]."<br>";
}
die('<br><a href="'.$source.'" style="color: #fff">&lt;&lt; Back to ICEcoder</a>');
}
renameOldVersion();
}
function renameOldVersion() {
if (is_dir(PATH)) {
echo 'Postfixing oldVersion dir with a timestamp...<br>';
rename(PATH,trim(PATH,"/")."-".time());
@@ -37,10 +64,10 @@ function copyOldVersion() {
echo 'Moving current ICEcoder files...<br>';
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 {