GH-1060 tweaks to new update mechanism - logging

This commit is contained in:
Petr Mrázek 2015-06-09 00:48:25 +02:00
parent 82e05661d2
commit 64b70acac1

View File

@ -647,6 +647,10 @@ static QFile::Permissions unixModeToPermissions(const int mode)
void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationList operations) void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationList operations)
{ {
qint64 pid = -1;
QStringList args;
bool started = false;
qDebug() << "Installing updates."; qDebug() << "Installing updates.";
#ifdef WINDOWS #ifdef WINDOWS
QString finishCmd = applicationFilePath(); QString finishCmd = applicationFilePath();
@ -687,13 +691,21 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
if(replaced.exists()) if(replaced.exists())
{ {
QString backupFilePath = PathCombine(backupPath, replaced.completeBaseName()); QString backupFilePath = PathCombine(backupPath, replaced.completeBaseName());
QFile::rename(replaced.absoluteFilePath(), backupFilePath); if(!QFile::rename(replaced.absoluteFilePath(), backupFilePath))
{
qWarning() << "Couldn't rename:" << replaced.absoluteFilePath() << "to" << backupFilePath;
goto FAILED;
}
BackupEntry be; BackupEntry be;
be.orig = replaced.absoluteFilePath(); be.orig = replaced.absoluteFilePath();
be.backup = backupFilePath; be.backup = backupFilePath;
backups.append(be); backups.append(be);
} }
QFile::copy(op.file, replaced.absoluteFilePath()); if(!QFile::copy(op.file, replaced.absoluteFilePath()))
{
qWarning() << "Couldn't copy:" << op.file << "to" << replaced.absoluteFilePath();
goto FAILED;
}
QFile::setPermissions(replaced.absoluteFilePath(), unixModeToPermissions(op.mode)); QFile::setPermissions(replaced.absoluteFilePath(), unixModeToPermissions(op.mode));
} }
break; break;
@ -715,13 +727,13 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
} }
// try to start the new binary // try to start the new binary
qint64 pid = -1; args = qApp->arguments();
auto args = qApp->arguments();
args.removeFirst(); args.removeFirst();
QProcess::startDetached(finishCmd, args, QDir::currentPath(), &pid); started = QProcess::startDetached(finishCmd, args, QDir::currentPath(), &pid);
// failed to start... ? // failed to start... ?
if(pid == -1) if(!started || pid == -1)
{ {
qWarning() << "Couldn't start new process properly!";
goto FAILED; goto FAILED;
} }
// now clean up the backed up stuff. // now clean up the backed up stuff.
@ -737,14 +749,17 @@ void MultiMC::installUpdates(const QString updateFilesDir, GoUpdate::OperationLi
return; return;
FAILED: FAILED:
qWarning() << "Update failed!";
// if the above failed, roll back changes // if the above failed, roll back changes
for(auto backup:backups) for(auto backup:backups)
{ {
qWarning() << "restoring" << backup.orig << "from" << backup.backup;
QFile::remove(backup.orig); QFile::remove(backup.orig);
QFile::rename(backup.backup, backup.orig); QFile::rename(backup.backup, backup.orig);
} }
for(auto backup:trashcan) for(auto backup:trashcan)
{ {
qWarning() << "restoring" << backup.orig << "from" << backup.backup;
QFile::rename(backup.backup, backup.orig); QFile::rename(backup.backup, backup.orig);
} }
// and do nothing // and do nothing