Skip to content

Commit 94eff75

Browse files
committed
fix: prevent stdout data loss in CommandRunner
1 parent 86e1b3d commit 94eff75

1 file changed

Lines changed: 41 additions & 46 deletions

File tree

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,48 @@
11
#include "commandrunner.h"
22
#include <QProcess>
33

4-
CommandRunner::CommandRunner(QObject *parent)
5-
: QObject(parent)
6-
{}
7-
8-
CommandRunner::Result CommandRunner::run(const QString &program, const QStringList &args)
9-
{
10-
QProcess process;
11-
12-
// Tüm stdout verisini biriktir — hem anlık sinyal hem de sonuç için
13-
QByteArray stdoutBuf;
14-
15-
// Stdout'u anlık olarak sinyal olarak ilet
16-
connect(&process, &QProcess::readyReadStandardOutput, this, [&]() {
17-
const QByteArray data = process.readAllStandardOutput();
18-
stdoutBuf.append(data);
19-
const QString line = QString::fromUtf8(data).trimmed();
20-
if (!line.isEmpty())
21-
emit outputLine(line);
22-
});
23-
24-
process.start(program, args);
25-
26-
if (!process.waitForStarted(3000)) {
27-
return Result {
28-
.exitCode = -1,
29-
.stdout = {},
30-
.stderr = QStringLiteral("Failed to start: %1").arg(program),
31-
};
32-
}
33-
34-
process.waitForFinished(-1);
35-
36-
// waitForFinished sonrası kalan veriyi de oku
37-
const QByteArray remaining = process.readAllStandardOutput();
38-
stdoutBuf.append(remaining);
39-
40-
return Result {
41-
.exitCode = process.exitCode(),
42-
.stdout = QString::fromUtf8(stdoutBuf),
43-
.stderr = QString::fromUtf8(process.readAllStandardError()),
4+
CommandRunner::CommandRunner(QObject *parent) : QObject(parent) {}
5+
6+
CommandRunner::Result CommandRunner::run(const QString &program,
7+
const QStringList &args) {
8+
QProcess process;
9+
QByteArray stdoutBuffer;
10+
11+
// Stdout'u anlık olarak sinyal olarak ilet
12+
connect(&process, &QProcess::readyReadStandardOutput, this, [&]() {
13+
const QByteArray chunk = process.readAllStandardOutput();
14+
stdoutBuffer.append(chunk);
15+
16+
const QString line = QString::fromUtf8(chunk).trimmed();
17+
if (!line.isEmpty())
18+
emit outputLine(line);
19+
});
20+
21+
process.start(program, args);
22+
23+
if (!process.waitForStarted(3000)) {
24+
return Result{
25+
.exitCode = -1,
26+
.stdout = {},
27+
.stderr = QStringLiteral("Failed to start: %1").arg(program),
4428
};
29+
}
30+
31+
process.waitForFinished(-1);
32+
33+
stdoutBuffer.append(process.readAllStandardOutput());
34+
35+
return Result{
36+
.exitCode = process.exitCode(),
37+
.stdout = QString::fromUtf8(stdoutBuffer),
38+
.stderr = QString::fromUtf8(process.readAllStandardError()),
39+
};
4540
}
4641

47-
CommandRunner::Result CommandRunner::runAsRoot(const QString &program, const QStringList &args)
48-
{
49-
// pkexec ile privilege escalation — sudo yerine PolicyKit kullanıyoruz
50-
QStringList pkexecArgs;
51-
pkexecArgs << program << args;
52-
return run(QStringLiteral("pkexec"), pkexecArgs);
42+
CommandRunner::Result CommandRunner::runAsRoot(const QString &program,
43+
const QStringList &args) {
44+
// pkexec ile privilege escalation — sudo yerine PolicyKit kullanıyoruz
45+
QStringList pkexecArgs;
46+
pkexecArgs << program << args;
47+
return run(QStringLiteral("pkexec"), pkexecArgs);
5348
}

0 commit comments

Comments
 (0)