Remove ExternalCommand::waitFor.
This is no longer used with KAuth. ExternalCommand::start now waits until command finishes.
This commit is contained in:
parent
1b39be28ee
commit
2579d04229
|
@ -167,12 +167,7 @@ bool fat12::updateUUID(Report& report, const QString& deviceNode) const
|
||||||
|
|
||||||
ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode , QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=39") });
|
ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode , QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=39") });
|
||||||
|
|
||||||
if (!cmd.write(QByteArray(uuid, sizeof(uuid))))
|
cmd.write(QByteArray(uuid, sizeof(uuid)));
|
||||||
return false;
|
return cmd.start();
|
||||||
|
|
||||||
if (!cmd.start())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return cmd.waitFor(-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,12 +59,7 @@ bool fat32::updateUUID(Report& report, const QString& deviceNode) const
|
||||||
// HACK: replace this hack with fatlabel "-i" (dosfstools 4.2)
|
// HACK: replace this hack with fatlabel "-i" (dosfstools 4.2)
|
||||||
ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode, QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=67") });
|
ExternalCommand cmd(report, QStringLiteral("dd"), { QStringLiteral("of=") + deviceNode, QStringLiteral("bs=1"), QStringLiteral("count=4"), QStringLiteral("seek=67") });
|
||||||
|
|
||||||
if (!cmd.write(QByteArray(uuid, sizeof(uuid))))
|
cmd.write(QByteArray(uuid, sizeof(uuid)));
|
||||||
return false;
|
return cmd.start();
|
||||||
|
|
||||||
if (!cmd.start())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return cmd.waitFor(-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ qint64 jfs::readUsedCapacity(const QString& deviceNode) const
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(QStringLiteral("jfs_debugfs"), QStringList() << deviceNode);
|
ExternalCommand cmd(QStringLiteral("jfs_debugfs"), QStringList() << deviceNode);
|
||||||
|
|
||||||
if (cmd.write(QByteArrayLiteral("dm")) && cmd.start() && cmd.waitFor()) {
|
if (cmd.write(QByteArrayLiteral("dm")) && cmd.start()) {
|
||||||
qint64 blockSize = -1;
|
qint64 blockSize = -1;
|
||||||
QRegularExpression re(QStringLiteral("Block Size: (\\d+)"));
|
QRegularExpression re(QStringLiteral("Block Size: (\\d+)"));
|
||||||
QRegularExpressionMatch reBlockSize = re.match(cmd.output());
|
QRegularExpressionMatch reBlockSize = re.match(cmd.output());
|
||||||
|
|
|
@ -131,8 +131,7 @@ bool luks::create(Report& report, const QString& deviceNode)
|
||||||
QStringLiteral("luksFormat"),
|
QStringLiteral("luksFormat"),
|
||||||
deviceNode });
|
deviceNode });
|
||||||
if (!( createCmd.write(m_passphrase.toLocal8Bit() + '\n') &&
|
if (!( createCmd.write(m_passphrase.toLocal8Bit() + '\n') &&
|
||||||
createCmd.start(-1) &&
|
createCmd.start(-1) && createCmd.exitCode() == 0))
|
||||||
createCmd.waitFor() && createCmd.exitCode() == 0))
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +141,7 @@ bool luks::create(Report& report, const QString& deviceNode)
|
||||||
deviceNode,
|
deviceNode,
|
||||||
suggestedMapperName(deviceNode) });
|
suggestedMapperName(deviceNode) });
|
||||||
|
|
||||||
if (!( openCmd.write(m_passphrase.toLocal8Bit() + '\n') && openCmd.start(-1) && openCmd.waitFor()))
|
if (!( openCmd.write(m_passphrase.toLocal8Bit() + '\n') && openCmd.start(-1)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
setPayloadSize();
|
setPayloadSize();
|
||||||
|
@ -267,8 +266,7 @@ bool luks::cryptOpen(QWidget* parent, const QString& deviceNode)
|
||||||
suggestedMapperName(deviceNode) });
|
suggestedMapperName(deviceNode) });
|
||||||
|
|
||||||
if (!( openCmd.write(passphrase.toLocal8Bit() + '\n') &&
|
if (!( openCmd.write(passphrase.toLocal8Bit() + '\n') &&
|
||||||
openCmd.start(-1) &&
|
openCmd.start(-1) && openCmd.exitCode() == 0) )
|
||||||
openCmd.waitFor() && openCmd.exitCode() == 0) )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_innerFs) {
|
if (m_innerFs) {
|
||||||
|
@ -691,7 +689,7 @@ void luks::setPayloadSize()
|
||||||
|
|
||||||
bool luks::testPassphrase(const QString& deviceNode, const QString& passphrase) const {
|
bool luks::testPassphrase(const QString& deviceNode, const QString& passphrase) const {
|
||||||
ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("open"), QStringLiteral("--tries"), QStringLiteral("1"), QStringLiteral("--test-passphrase"), deviceNode });
|
ExternalCommand cmd(QStringLiteral("cryptsetup"), { QStringLiteral("open"), QStringLiteral("--tries"), QStringLiteral("1"), QStringLiteral("--test-passphrase"), deviceNode });
|
||||||
if (cmd.write(passphrase.toLocal8Bit() + '\n') && cmd.start(-1) && cmd.waitFor() && cmd.exitCode() == 0)
|
if (cmd.write(passphrase.toLocal8Bit() + '\n') && cmd.start(-1) && cmd.exitCode() == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -57,7 +57,7 @@ bool luks2::create(Report& report, const QString& deviceNode)
|
||||||
QStringLiteral("luksFormat"),
|
QStringLiteral("luksFormat"),
|
||||||
deviceNode });
|
deviceNode });
|
||||||
if (!( createCmd.write(m_passphrase.toLocal8Bit() + '\n') &&
|
if (!( createCmd.write(m_passphrase.toLocal8Bit() + '\n') &&
|
||||||
createCmd.start(-1) && createCmd.waitFor() && createCmd.exitCode() == 0))
|
createCmd.start(-1) && createCmd.exitCode() == 0))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ bool luks2::create(Report& report, const QString& deviceNode)
|
||||||
deviceNode,
|
deviceNode,
|
||||||
suggestedMapperName(deviceNode) });
|
suggestedMapperName(deviceNode) });
|
||||||
|
|
||||||
if (!( openCmd.write(m_passphrase.toLocal8Bit() + '\n') && openCmd.start(-1) && openCmd.waitFor()))
|
if (!( openCmd.write(m_passphrase.toLocal8Bit() + '\n') && openCmd.start(-1)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
setPayloadSize();
|
setPayloadSize();
|
||||||
|
@ -99,8 +99,8 @@ bool luks2::resize(Report& report, const QString& deviceNode, qint64 newLength)
|
||||||
return false;
|
return false;
|
||||||
cryptResizeCmd.write(m_passphrase.toLocal8Bit() + '\n');
|
cryptResizeCmd.write(m_passphrase.toLocal8Bit() + '\n');
|
||||||
}
|
}
|
||||||
cryptResizeCmd.start(-1);
|
if (!cryptResizeCmd.start(-1))
|
||||||
cryptResizeCmd.waitFor();
|
return false;
|
||||||
if ( cryptResizeCmd.exitCode() == 0 )
|
if ( cryptResizeCmd.exitCode() == 0 )
|
||||||
return m_innerFs->resize(report, mapperName(), m_PayloadSize);
|
return m_innerFs->resize(report, mapperName(), m_PayloadSize);
|
||||||
}
|
}
|
||||||
|
@ -115,8 +115,8 @@ bool luks2::resize(Report& report, const QString& deviceNode, qint64 newLength)
|
||||||
return false;
|
return false;
|
||||||
cryptResizeCmd.write(m_passphrase.toLocal8Bit() + '\n');
|
cryptResizeCmd.write(m_passphrase.toLocal8Bit() + '\n');
|
||||||
}
|
}
|
||||||
cryptResizeCmd.start(-1);
|
if (!cryptResizeCmd.start(-1))
|
||||||
cryptResizeCmd.waitFor();
|
return false;
|
||||||
if ( cryptResizeCmd.exitCode() == 0 )
|
if ( cryptResizeCmd.exitCode() == 0 )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,6 @@ bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const
|
||||||
Log() << xi18nc("@info:progress", "Could not write new start sector to partition <filename>%1</filename> when trying to update the NTFS boot sector.", deviceNode);
|
Log() << xi18nc("@info:progress", "Could not write new start sector to partition <filename>%1</filename> when trying to update the NTFS boot sector.", deviceNode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cmd.waitFor(-1);
|
|
||||||
|
|
||||||
// Also update backup NTFS boot sector located at the end of the partition
|
// Also update backup NTFS boot sector located at the end of the partition
|
||||||
// NOTE: this should fail if filesystem does not span the whole partition
|
// NOTE: this should fail if filesystem does not span the whole partition
|
||||||
|
@ -207,7 +206,6 @@ bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const
|
||||||
Log() << xi18nc("@info:progress", "Could not write new start sector to partition <filename>%1</filename> when trying to update the NTFS boot sector.", deviceNode);
|
Log() << xi18nc("@info:progress", "Could not write new start sector to partition <filename>%1</filename> when trying to update the NTFS boot sector.", deviceNode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cmd2.waitFor(-1);
|
|
||||||
|
|
||||||
Log() << xi18nc("@info:progress", "Updated NTFS boot sector for partition <filename>%1</filename> successfully.", deviceNode);
|
Log() << xi18nc("@info:progress", "Updated NTFS boot sector for partition <filename>%1</filename> successfully.", deviceNode);
|
||||||
|
|
||||||
|
|
|
@ -113,15 +113,12 @@ bool ocfs2::create(Report& report, const QString& deviceNode)
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(report, QStringLiteral("mkfs.ocfs2"), { deviceNode });
|
ExternalCommand cmd(report, QStringLiteral("mkfs.ocfs2"), { deviceNode });
|
||||||
|
|
||||||
if (cmd.write("y\n"))
|
cmd.write("y\n");
|
||||||
{
|
if (!cmd.start())
|
||||||
cmd.start();
|
|
||||||
cmd.waitFor(-1);
|
|
||||||
|
|
||||||
return cmd.exitCode() == 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return cmd.exitCode() == 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ocfs2::resize(Report& report, const QString& deviceNode, qint64 length) const
|
bool ocfs2::resize(Report& report, const QString& deviceNode, qint64 length) const
|
||||||
|
|
|
@ -162,7 +162,7 @@ bool reiserfs::resize(Report& report, const QString& deviceNode, qint64 length)
|
||||||
if (!cmd.start(-1))
|
if (!cmd.start(-1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return cmd.waitFor(-1) && (cmd.exitCode() == 0 || cmd.exitCode() == 256);
|
return cmd.exitCode() == 0 || cmd.exitCode() == 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reiserfs::resizeOnline(Report& report, const QString& deviceNode, const QString&, qint64 length) const
|
bool reiserfs::resizeOnline(Report& report, const QString& deviceNode, const QString&, qint64 length) const
|
||||||
|
|
|
@ -73,7 +73,7 @@ bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTable& pt
|
||||||
|
|
||||||
ExternalCommand createCommand(report, QStringLiteral("sfdisk"), { m_device->deviceNode() } );
|
ExternalCommand createCommand(report, QStringLiteral("sfdisk"), { m_device->deviceNode() } );
|
||||||
if ( createCommand.write(QByteArrayLiteral("label: ") + tableType +
|
if ( createCommand.write(QByteArrayLiteral("label: ") + tableType +
|
||||||
QByteArrayLiteral("\nwrite\n")) && createCommand.start(-1) && createCommand.waitFor() ) {
|
QByteArrayLiteral("\nwrite\n")) && createCommand.start(-1) ) {
|
||||||
return createCommand.output().contains(QStringLiteral("Script header accepted."));
|
return createCommand.output().contains(QStringLiteral("Script header accepted."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ QString SfdiskPartitionTable::createPartition(Report& report, const Partition& p
|
||||||
ExternalCommand createCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--force"), QStringLiteral("--append"), partition.devicePath() } );
|
ExternalCommand createCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--force"), QStringLiteral("--append"), partition.devicePath() } );
|
||||||
if ( createCommand.write(QByteArrayLiteral("start=") + QByteArray::number(partition.firstSector()) +
|
if ( createCommand.write(QByteArrayLiteral("start=") + QByteArray::number(partition.firstSector()) +
|
||||||
type +
|
type +
|
||||||
QByteArrayLiteral(" size=") + QByteArray::number(partition.length()) + QByteArrayLiteral("\nwrite\n")) && createCommand.start(-1) && createCommand.waitFor() ) {
|
QByteArrayLiteral(" size=") + QByteArray::number(partition.length()) + QByteArrayLiteral("\nwrite\n")) && createCommand.start(-1) ) {
|
||||||
QRegularExpression re(QStringLiteral("Created a new partition (\\d+)"));
|
QRegularExpression re(QStringLiteral("Created a new partition (\\d+)"));
|
||||||
QRegularExpressionMatch rem = re.match(createCommand.output());
|
QRegularExpressionMatch rem = re.match(createCommand.output());
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ bool SfdiskPartitionTable::updateGeometry(Report& report, const Partition& parti
|
||||||
if ( sfdiskCommand.write(QByteArrayLiteral("start=") + QByteArray::number(sectorStart) +
|
if ( sfdiskCommand.write(QByteArrayLiteral("start=") + QByteArray::number(sectorStart) +
|
||||||
QByteArrayLiteral(" size=") + QByteArray::number(sectorEnd - sectorStart + 1) +
|
QByteArrayLiteral(" size=") + QByteArray::number(sectorEnd - sectorStart + 1) +
|
||||||
QByteArrayLiteral("\nY\n"))
|
QByteArrayLiteral("\nY\n"))
|
||||||
&& sfdiskCommand.start(-1) && sfdiskCommand.waitFor() && sfdiskCommand.exitCode() == 0) {
|
&& sfdiskCommand.start(-1) && sfdiskCommand.exitCode() == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -251,32 +251,13 @@ bool ExternalCommand::write(const QByteArray& input)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Waits for the external command to finish.
|
|
||||||
@param timeout timeout to wait until the process finishes.
|
|
||||||
@return true on success
|
|
||||||
*/
|
|
||||||
bool ExternalCommand::waitFor(int timeout)
|
|
||||||
{
|
|
||||||
// closeWriteChannel();
|
|
||||||
/*
|
|
||||||
if (!waitForFinished(timeout)) {
|
|
||||||
if (report())
|
|
||||||
report()->line() << xi18nc("@info:status", "(Command timeout while running)");
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// onReadOutput();
|
|
||||||
Q_UNUSED(timeout)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Runs the command.
|
/** Runs the command.
|
||||||
@param timeout timeout to use for waiting when starting and when waiting for the process to finish
|
@param timeout timeout to use for waiting when starting and when waiting for the process to finish
|
||||||
@return true on success
|
@return true on success
|
||||||
*/
|
*/
|
||||||
bool ExternalCommand::run(int timeout)
|
bool ExternalCommand::run(int timeout)
|
||||||
{
|
{
|
||||||
return start(timeout) && waitFor(timeout)/* && exitStatus() == 0*/;
|
return start(timeout) /* && exitStatus() == 0*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalCommand::onReadOutput()
|
void ExternalCommand::onReadOutput()
|
||||||
|
|
|
@ -88,7 +88,6 @@ public:
|
||||||
|
|
||||||
bool startCopyBlocks();
|
bool startCopyBlocks();
|
||||||
bool start(int timeout = 30000);
|
bool start(int timeout = 30000);
|
||||||
bool waitFor(int timeout = 30000);
|
|
||||||
bool run(int timeout = 30000);
|
bool run(int timeout = 30000);
|
||||||
|
|
||||||
/**< @return the exit code */
|
/**< @return the exit code */
|
||||||
|
|
Loading…
Reference in New Issue