Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb29667' into 'master'
[vault] add helper functions for running QProcesses. JB#29667

See merge request mer-core/vault!12
  • Loading branch information
MikeSalmela committed Nov 15, 2019
2 parents c664355 + e19028e commit 9ae3a60
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
31 changes: 31 additions & 0 deletions lib/unit.cpp
Expand Up @@ -14,6 +14,9 @@
#include <qtaround/debug.hpp>

#include <QString>
#include <QProcess>
#include <QDebug>
#include <QLoggingCategory>

namespace os = qtaround::os;
namespace error = qtaround::error;
Expand All @@ -22,6 +25,8 @@ namespace util = qtaround::util;
namespace json = qtaround::json;
namespace debug = qtaround::debug;

Q_LOGGING_CATEGORY(lcBackup, "org.sailfishos.backup", QtWarningMsg)

namespace vault { namespace unit {

static const unsigned current_version = 1;
Expand Down Expand Up @@ -496,4 +501,30 @@ int execute(std::unique_ptr<sys::GetOpt>, QVariantMap const &info)
return 0;
}

int execute(QVariantMap const &info)
{
try {
Operation op(getopt(), info);
op.execute();
} catch (error::Error const &e) {
qCDebug(lcBackup) << e;
return 1;
}
return 0;
}

int runProcess(const QString &program, const QStringList &args)
{
QProcess ps;
ps.start(program, args);
ps.waitForFinished(-1);
if (ps.exitStatus() == QProcess::CrashExit || ps.exitCode() != 0) {
qCDebug(lcBackup) << ps.program() << "failed";
qCDebug(lcBackup) << ps.readAllStandardError();
qCDebug(lcBackup) << ps.readAllStandardOutput();
return 1;
}
return 0;
}

}} // namespace vault::unit
6 changes: 5 additions & 1 deletion lib/unit.h
Expand Up @@ -9,7 +9,7 @@
*/

#include <memory>

#include <QString>
#include <QVariantMap>

namespace qtaround { namespace sys { class GetOpt; }}
Expand All @@ -21,6 +21,10 @@ options_uptr getopt();

int execute(options_uptr, QVariantMap const &info);

int execute(QVariantMap const &info);

int runProcess(const QString &program, const QStringList &args);

}}

#endif // _CUTES_UNIT_HPP_
4 changes: 2 additions & 2 deletions rpm/vault.spec
@@ -1,8 +1,8 @@
Summary: Incremental backup/restore framework
Name: vault
Version: 1.0.0
Version: 1.0.1
Release: 1
License: LGPLv2.1
License: LGPLv2
Group: Development/Libraries
URL: https://git.sailfishos.org/mer-core/vault
Source0: %{name}-%{version}.tar.bz2
Expand Down

0 comments on commit 9ae3a60

Please sign in to comment.