62 lines
1.9 KiB
Diff
62 lines
1.9 KiB
Diff
From c836c3371126640a1e50d027c46224a12a1a85ac Mon Sep 17 00:00:00 2001
|
|
From: Ray Donnelly <mingw.android@gmail.com>
|
|
Date: Tue, 30 Sep 2014 14:43:39 +0100
|
|
Subject: [PATCH 04/14] Remove redundancy in UnixCommand's exe checking
|
|
functions
|
|
|
|
Check the result of UnixCommand::discoverBinaryPath() not
|
|
being empty in UnixCommand::hasTheExecutable() instead of
|
|
repeating much the same code.
|
|
---
|
|
src/unixcommand.cpp | 20 +++++++-------------
|
|
1 file changed, 7 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/src/unixcommand.cpp b/src/unixcommand.cpp
|
|
index 3f38757..071d0a8 100644
|
|
--- a/src/unixcommand.cpp
|
|
+++ b/src/unixcommand.cpp
|
|
@@ -82,6 +82,7 @@ QString UnixCommand::runCurlCommand(const QString& commandToRun){
|
|
QString UnixCommand::discoverBinaryPath(const QString& binary){
|
|
QProcess proc;
|
|
proc.setProcessEnvironment(getEnv());
|
|
+ proc.setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
proc.start("/bin/sh -c \"which " + binary + "\"");
|
|
proc.waitForFinished();
|
|
@@ -90,6 +91,11 @@ QString UnixCommand::discoverBinaryPath(const QString& binary){
|
|
proc.close();
|
|
res = res.remove('\n');
|
|
|
|
+ if (res.count("which"))
|
|
+ res.clear();
|
|
+
|
|
+ if (!res.isEmpty()) return res;
|
|
+
|
|
//If it still didn't find it, try "/sbin" dir...
|
|
if (res.isEmpty()){
|
|
QFile fbin("/sbin/" + binary);
|
|
@@ -588,19 +594,7 @@ bool UnixCommand::doInternetPingTest()
|
|
*/
|
|
bool UnixCommand::hasTheExecutable( const QString& exeName )
|
|
{
|
|
- //std::cout << "Searching for the executable: " << exeName.toLatin1().data() << std::endl;
|
|
-
|
|
- QProcess proc;
|
|
- proc.setProcessChannelMode(QProcess::MergedChannels);
|
|
- QString sParam = "\"which " + exeName + "\"";
|
|
- proc.start("/bin/sh -c " + sParam);
|
|
- proc.waitForFinished();
|
|
-
|
|
- QString out = proc.readAllStandardOutput();
|
|
- proc.close();
|
|
-
|
|
- if (out.isEmpty() || out.count("which") > 0) return false;
|
|
- else return true;
|
|
+ return (!discoverBinaryPath(exeName).isEmpty());
|
|
}
|
|
|
|
/*
|
|
--
|
|
2.8.2
|
|
|