[Pkg-owncloud-commits] [owncloud-client] 346/498: Utility: Added function versionOfInstalledBinary()

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:05 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 2f2ae09190fd9355791aef08ea959a25cbad3b35
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Thu Jul 16 18:16:16 2015 +0200

    Utility: Added function versionOfInstalledBinary()
    
    It calls the binary with param --version and returns the first line of
    the output. For owncloud, that is the version string.
---
 src/libsync/utility.cpp | 29 +++++++++++++++++++++++++++++
 src/libsync/utility.h   |  7 +++++++
 test/testutility.h      | 11 +++++++++++
 3 files changed, 47 insertions(+)

diff --git a/src/libsync/utility.cpp b/src/libsync/utility.cpp
index 3feefcb..6a999b9 100644
--- a/src/libsync/utility.cpp
+++ b/src/libsync/utility.cpp
@@ -393,6 +393,35 @@ void Utility::crash()
     *a = 1;
 }
 
+// read the output of the owncloud --version command from the owncloud
+// version that is on disk. This works for most versions of the client,
+// because clients that do not yet know the --version flag return the
+// version in the first line of the help output :-)
+//
+// This version only delivers output on linux, as Mac and Win get their
+// restarting from the installer.
+QByteArray Utility::versionOfInstalledBinary( const QString& command )
+{
+    QByteArray re;
+    if( isLinux() ) {
+        QString binary(command);
+        if( binary.isEmpty() ) {
+            binary = qApp->arguments()[0];
+        }
+        QStringList params;
+        params << QLatin1String("--version");
+        QProcess process;
+        process.start(binary, params);
+        process.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
+        re = process.readAllStandardOutput();
+        int newline = re.indexOf(QChar('\n'));
+        if( newline > 0 ) {
+            re.truncate( newline );
+        }
+    }
+    return re;
+}
+
 static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END";
 
 void Utility::StopWatch::start()
diff --git a/src/libsync/utility.h b/src/libsync/utility.h
index 957f5e2..40e7961 100644
--- a/src/libsync/utility.h
+++ b/src/libsync/utility.h
@@ -98,6 +98,13 @@ namespace Utility
     // if false, the two cases are two different files.
     OWNCLOUDSYNC_EXPORT bool fsCasePreserving();
 
+    // Call the given command with the switch --version and retrun the first line
+    // of the output.
+    // If command is empty, the function calls the running application which, on
+    // Linux, might have changed while this one is running.
+    // For Mac and Windows, it returns QString()
+    OWNCLOUDSYNC_EXPORT QByteArray versionOfInstalledBinary(const QString& command = QString() );
+
     class OWNCLOUDSYNC_EXPORT StopWatch {
     private:
         QHash<QString, quint64> _lapTimes;
diff --git a/test/testutility.h b/test/testutility.h
index 8d29dad..022db10 100644
--- a/test/testutility.h
+++ b/test/testutility.h
@@ -103,6 +103,17 @@ private slots:
 
 
     }
+
+    void testVersionOfInstalledBinary()
+    {
+	if( isLinux() ) {
+                QString ver = versionOfInstalledBinary("/home/kf/owncloud.com/buildmirall/bin/owncloud");
+		qDebug() << "Version of installed ownCloud Binary: " << ver;
+		QVERIFY( !ver.isEmpty()); 
+	} else {
+		QVERIFY( versionOfInstalledBinary().isEmpty());
+	}
+    }
 };
 
 #endif

-- 
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