244 lines
8.3 KiB
Diff
244 lines
8.3 KiB
Diff
From e16f29e19a01f4988f309c2fd083cb92545addc8 Mon Sep 17 00:00:00 2001
|
|
From: Ray Donnelly <mingw.android@gmail.com>
|
|
Date: Sat, 27 Sep 2014 15:23:27 +0100
|
|
Subject: [PATCH 02/14] Use a shared QProcessEnvironment
|
|
|
|
This reduces a lot of repetition. Environment variables
|
|
LANG, LC_MESSAGES, LC_ALL are set to "C" for all cases.
|
|
---
|
|
src/unixcommand.cpp | 78 +++++++++++------------------------------------------
|
|
src/unixcommand.h | 15 +++++++++++
|
|
2 files changed, 31 insertions(+), 62 deletions(-)
|
|
|
|
diff --git a/src/unixcommand.cpp b/src/unixcommand.cpp
|
|
index 9fd8779..3f38757 100644
|
|
--- a/src/unixcommand.cpp
|
|
+++ b/src/unixcommand.cpp
|
|
@@ -36,6 +36,7 @@
|
|
*/
|
|
|
|
QFile *UnixCommand::m_temporaryFile = 0;
|
|
+QProcessEnvironment *UnixCommand::m_env = 0;
|
|
|
|
/*
|
|
* Executes given command and returns the StandardError Output.
|
|
@@ -43,12 +44,7 @@ QFile *UnixCommand::m_temporaryFile = 0;
|
|
QString UnixCommand::runCommand(const QString& commandToRun)
|
|
{
|
|
QProcess proc;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.remove("LANG");
|
|
- env.remove("LC_MESSAGES");
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- proc.setProcessEnvironment(env);
|
|
+ proc.setProcessEnvironment(getEnv());
|
|
proc.start(commandToRun);
|
|
proc.waitForStarted();
|
|
proc.waitForFinished(-1);
|
|
@@ -64,10 +60,7 @@ QString UnixCommand::runCommand(const QString& commandToRun)
|
|
*/
|
|
QString UnixCommand::runCurlCommand(const QString& commandToRun){
|
|
QProcess proc;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- proc.setProcessEnvironment(env);
|
|
+ proc.setProcessEnvironment(getEnv());
|
|
proc.start(commandToRun);
|
|
proc.waitForStarted();
|
|
proc.waitForFinished(-1);
|
|
@@ -88,10 +81,7 @@ QString UnixCommand::runCurlCommand(const QString& commandToRun){
|
|
*/
|
|
QString UnixCommand::discoverBinaryPath(const QString& binary){
|
|
QProcess proc;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- proc.setProcessEnvironment(env);
|
|
+ proc.setProcessEnvironment(getEnv());
|
|
|
|
proc.start("/bin/sh -c \"which " + binary + "\"");
|
|
proc.waitForFinished();
|
|
@@ -139,11 +129,7 @@ QByteArray UnixCommand::performQuery(const QStringList args)
|
|
QByteArray result("");
|
|
QProcess pacman;
|
|
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- env.insert("LC_ALL", "C");
|
|
- pacman.setProcessEnvironment(env);
|
|
+ pacman.setProcessEnvironment(getEnv());
|
|
|
|
pacman.start("pacman", args);
|
|
pacman.waitForFinished();
|
|
@@ -162,11 +148,7 @@ QByteArray UnixCommand::performQuery(const QString &args)
|
|
QByteArray result("");
|
|
QProcess pacman;
|
|
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- env.insert("LC_ALL", "C");
|
|
- pacman.setProcessEnvironment(env);
|
|
+ pacman.setProcessEnvironment(getEnv());
|
|
|
|
pacman.start("pacman " + args);
|
|
pacman.waitForFinished();
|
|
@@ -183,10 +165,7 @@ QByteArray UnixCommand::performAURCommand(const QString &args)
|
|
QByteArray result("");
|
|
QProcess aur;
|
|
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- aur.setProcessEnvironment(env);
|
|
+ aur.setProcessEnvironment(getEnv());
|
|
|
|
aur.start(StrConstants::getForeignRepositoryToolName() + " " + args);
|
|
aur.waitForFinished(-1);
|
|
@@ -226,11 +205,8 @@ QByteArray UnixCommand::getAURPackageList(const QString &searchString)
|
|
{
|
|
QByteArray result("");
|
|
QProcess aur;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
|
|
- aur.setProcessEnvironment(env);
|
|
+ aur.setProcessEnvironment(getEnv());
|
|
|
|
if (UnixCommand::getLinuxDistro() == ectn_KAOS)
|
|
aur.start(StrConstants::getForeignRepositoryToolName() + " -l ");
|
|
@@ -419,8 +395,7 @@ bool UnixCommand::isPkgfileInstalled()
|
|
{
|
|
QProcess pkgfile;
|
|
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- pkgfile.setProcessEnvironment(env);
|
|
+ pkgfile.setProcessEnvironment(getEnv());
|
|
|
|
pkgfile.start("pkgfile -V");
|
|
pkgfile.waitForFinished();
|
|
@@ -437,10 +412,7 @@ QByteArray UnixCommand::getPackageContentsUsingPkgfile(const QString &pkgName)
|
|
{
|
|
QByteArray result("");
|
|
QProcess pkgfile;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- pkgfile.setProcessEnvironment(env);
|
|
+ pkgfile.setProcessEnvironment(getEnv());
|
|
|
|
pkgfile.start("pkgfile -l " + pkgName);
|
|
pkgfile.waitForFinished();
|
|
@@ -475,10 +447,7 @@ QString UnixCommand::getPackageByFilePath(const QString &filePath)
|
|
QStringList UnixCommand::getFilePathSuggestions(const QString &file)
|
|
{
|
|
QProcess slocate;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- slocate.setProcessEnvironment(env);
|
|
+ slocate.setProcessEnvironment(getEnv());
|
|
slocate.start("slocate -l 8 " + file);
|
|
slocate.waitForFinished();
|
|
|
|
@@ -545,10 +514,7 @@ QString UnixCommand::getSystemArchitecture()
|
|
{
|
|
QStringList slParam;
|
|
QProcess proc;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- proc.setProcessEnvironment(env);
|
|
+ proc.setProcessEnvironment(getEnv());
|
|
|
|
slParam << "-m";
|
|
proc.start("uname", slParam);
|
|
@@ -602,10 +568,7 @@ bool UnixCommand::hasInternetConnection()
|
|
bool UnixCommand::doInternetPingTest()
|
|
{
|
|
QProcess ping;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- ping.setProcessEnvironment(env);
|
|
+ ping.setProcessEnvironment(getEnv());
|
|
|
|
if (UnixCommand::getLinuxDistro() == ectn_MOOOSLINUX)
|
|
ping.start("torsocks ping -c 1 -W 3 www.google.com");
|
|
@@ -684,10 +647,7 @@ void UnixCommand::execCommandAsNormalUser(const QString &pCommand)
|
|
void UnixCommand::execCommand(const QString &pCommand)
|
|
{
|
|
QProcess p;
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- p.setProcessEnvironment(env);
|
|
+ p.setProcessEnvironment(getEnv());
|
|
|
|
p.start(WMHelper::getSUCommand() + "\"" + pCommand + "\"");
|
|
p.waitForFinished(-1);
|
|
@@ -716,10 +676,7 @@ QByteArray UnixCommand::getCommandOutput(const QString &pCommand)
|
|
bool UnixCommand::isTextFile(const QString& fileName)
|
|
{
|
|
QProcess *p = new QProcess();
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- p->setProcessEnvironment(env);
|
|
+ p->setProcessEnvironment(getEnv());
|
|
|
|
QStringList s(fileName);
|
|
p->start( "file", s );
|
|
@@ -863,10 +820,7 @@ UnixCommand::UnixCommand(QObject *parent): QObject()
|
|
m_process = new QProcess(parent);
|
|
m_terminal = new Terminal(parent, SettingsManager::getTerminal());
|
|
|
|
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
- env.insert("LANG", "C");
|
|
- env.insert("LC_MESSAGES", "C");
|
|
- m_process->setProcessEnvironment(env);
|
|
+ m_process->setProcessEnvironment(getEnv());
|
|
|
|
QObject::connect(m_process, SIGNAL( started() ), this,
|
|
SIGNAL( started() ));
|
|
diff --git a/src/unixcommand.h b/src/unixcommand.h
|
|
index 87d7792..b72c193 100644
|
|
--- a/src/unixcommand.h
|
|
+++ b/src/unixcommand.h
|
|
@@ -44,6 +44,7 @@ private:
|
|
Terminal *m_terminal;
|
|
QProcess *m_process;
|
|
static QFile *m_temporaryFile;
|
|
+ static QProcessEnvironment *m_env;
|
|
|
|
public:
|
|
UnixCommand(QObject *parent);
|
|
@@ -115,6 +116,20 @@ public:
|
|
return (uid == 0); //Returns TRUE if root is running Octopi
|
|
}
|
|
|
|
+ static QProcessEnvironment const& getEnv(){
|
|
+ if (!m_env)
|
|
+ {
|
|
+ m_env = new QProcessEnvironment(QProcessEnvironment::systemEnvironment());
|
|
+ m_env->remove("LANG");
|
|
+ m_env->remove("LC_MESSAGES");
|
|
+ m_env->remove("LC_ALL");
|
|
+ m_env->insert("LANG", "C");
|
|
+ m_env->insert("LC_MESSAGES", "C");
|
|
+ m_env->insert("LC_ALL", "C");
|
|
+ }
|
|
+ return *m_env;
|
|
+ }
|
|
+
|
|
static QFile* getTemporaryFile(){
|
|
QTime time = QTime::currentTime();
|
|
qsrand(time.minute() + time.second() + time.msec());
|
|
--
|
|
2.8.2
|
|
|