[Pkg-owncloud-commits] [owncloud-client] 355/498: Application: On Linux, restart the app if a different version is on HD.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:06 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 92513207eb954173ad626d65bc1e0f83e5f0e9c9
Author: Klaas Freitag <freitag at owncloud.com>
Date: Fri Jul 17 12:12:00 2015 +0200
Application: On Linux, restart the app if a different version is on HD.
Together with the updater timer, check on linux, if the version on the
disk has still the same version string as the one that is running. If
not, restart if nothing is currently syncing.
---
src/gui/application.cpp | 15 +++++++++++++++
src/gui/application.h | 1 +
src/gui/folderman.cpp | 28 +++++++++++++++++++++++++++-
src/gui/folderman.h | 10 ++++++++++
4 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index a2ddb94..a494e56 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -176,6 +176,11 @@ Application::Application(int &argc, char **argv) :
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
+ // remember the version of the currently running binary. On Linux it might happen that the
+ // package management updates the package while the app is running. This is detected in the
+ // updater slot: If the installed binary on the hd has a different version than the one
+ // running, the running app is restart. That happens in folderman.
+ _runningAppVersion = Utility::versionOfInstalledBinary();
}
Application::~Application()
@@ -217,6 +222,16 @@ void Application::slotStartUpdateDetector()
{
Updater *updater = Updater::instance();
updater->backgroundCheckForUpdate();
+
+ if( Utility::isLinux() ) {
+ // on linux, check if the installed binary is still the same version
+ // as the one that is running. If not, restart if possible.
+ const QByteArray fsVersion = Utility::versionOfInstalledBinary();
+
+ if( !(fsVersion.isEmpty() || _runningAppVersion.isEmpty()) && fsVersion != _runningAppVersion ) {
+ _folderManager->slotScheduleAppRestart();
+ }
+ }
}
void Application::slotCheckConnection()
diff --git a/src/gui/application.h b/src/gui/application.h
index 44fbfdd..7827944 100644
--- a/src/gui/application.h
+++ b/src/gui/application.h
@@ -106,6 +106,7 @@ private:
bool _logFlush;
bool _userTriggeredConnect;
bool _debugMode;
+ QByteArray _runningAppVersion;
ClientProxy _proxy;
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 546d00d..c1fb70c 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -54,7 +54,8 @@ static qint64 msBetweenRequestAndSync = 2000;
FolderMan::FolderMan(QObject *parent) :
QObject(parent),
_currentSyncFolder(0),
- _syncEnabled( true )
+ _syncEnabled( true ),
+ _appRestartRequired(false)
{
Q_ASSERT(!_instance);
_instance = this;
@@ -466,6 +467,12 @@ void FolderMan::slotScheduleAllFolders()
}
}
+void FolderMan::slotScheduleAppRestart()
+{
+ _appRestartRequired = true;
+ qDebug() << "## Application restart requested!";
+}
+
/*
* if a folder wants to be synced, it calls this slot and is added
* to the queue. The slot to actually start a sync is called afterwards.
@@ -533,6 +540,11 @@ void FolderMan::slotRunOneEtagJob()
}
if (_currentEtagJob.isNull()) {
qDebug() << "No more remote ETag check jobs to schedule.";
+
+ /* now it might be a good time to check for restarting... */
+ if( _currentSyncFolder == NULL && _appRestartRequired ) {
+ restartApplication();
+ }
} else {
qDebug() << "Scheduling" << alias << "to check remote ETag";
_currentEtagJob->start(); // on destroy/end it will continue the queue via slotEtagJobDestroyed
@@ -1151,5 +1163,19 @@ QString FolderMan::checkPathValidityForNewFolder(const QString& path)
}
+void FolderMan::restartApplication()
+{
+ if( Utility::isLinux() ) {
+ // restart:
+ qDebug() << "### Restarting application NOW, PID" << qApp->applicationPid() << "is ending.";
+ qApp->quit();
+ QStringList args = qApp->arguments();
+ QString prg = args.takeFirst();
+
+ QProcess::startDetached(prg, args);
+ } else {
+ qDebug() << "On this platform we do not restart.";
+ }
+}
} // namespace OCC
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index f791773..1d0206b 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -146,6 +146,11 @@ public slots:
*/
void slotAccountStateChanged();
+ /**
+ * restart the client as soon as it is possible, ie. no folders syncing.
+ */
+ void slotScheduleAppRestart();
+
private slots:
// slot to take the next folder from queue and start syncing.
void slotStartScheduledFolderSync();
@@ -174,6 +179,9 @@ private:
QString getBackupName( QString fullPathName ) const;
void registerFolderMonitor( Folder *folder );
+ // restarts the application (Linux only)
+ void restartApplication();
+
QString unescapeAlias( const QString& ) const;
QSet<Folder*> _disabledFolders;
@@ -194,6 +202,8 @@ private:
/** When the timer expires one of the scheduled syncs will be started. */
QTimer _startScheduledSyncTimer;
+ bool _appRestartRequired;
+
static FolderMan *_instance;
explicit FolderMan(QObject *parent = 0);
friend class OCC::Application;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list