-
Notifications
You must be signed in to change notification settings - Fork 198
Fix: Prevent UI reset when new device inserted during write (#825) #914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
6d76a24
f8cfe68
6d63fbc
9f5aa75
3169c70
f1972ee
56c55a7
de28ba0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,8 +210,8 @@ bool LinuxDrive::write(ReleaseVariant *data) | |
| if (m_image->status() == ReleaseVariant::READY || m_image->status() == ReleaseVariant::FAILED || m_image->status() == ReleaseVariant::FAILED_VERIFICATION || m_image->status() == ReleaseVariant::FINISHED) | ||
| m_image->setStatus(ReleaseVariant::WRITING); | ||
|
|
||
| if (!m_process) | ||
| m_process = new QProcess(this); | ||
| // Create new process using unique_ptr | ||
| m_process.reset(new QProcess(this)); | ||
|
|
||
| QStringList args; | ||
| if (QFile::exists(qApp->applicationDirPath() + "/../helper/linux/helper")) { | ||
|
|
@@ -235,11 +235,11 @@ bool LinuxDrive::write(ReleaseVariant *data) | |
| mDebug() << this->metaObject()->className() << "Helper command will be" << args; | ||
| m_process->setArguments(args); | ||
|
|
||
| connect(m_process, &QProcess::readyRead, this, &LinuxDrive::onReadyRead); | ||
| connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int, QProcess::ExitStatus))); | ||
| connect(m_process.get(), &QProcess::readyRead, this, &LinuxDrive::onReadyRead); | ||
| connect(m_process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int, QProcess::ExitStatus))); | ||
| // TODO check if this is actually necessary - it should work just fine even without it | ||
| connect(m_process, &QProcess::errorOccurred, this, &LinuxDrive::onErrorOccurred); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process, &QProcess::terminate); | ||
| connect(m_process.get(), &QProcess::errorOccurred, this, &LinuxDrive::onErrorOccurred); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process.get(), &QProcess::terminate); | ||
|
|
||
| m_process->start(QIODevice::ReadOnly); | ||
|
|
||
|
|
@@ -250,7 +250,7 @@ void LinuxDrive::cancel() | |
| { | ||
| Drive::cancel(); | ||
|
||
| static bool beingCancelled = false; | ||
| if (m_process != nullptr && !beingCancelled) { | ||
| if (m_process && !beingCancelled) { | ||
| beingCancelled = true; | ||
| if (m_image) { | ||
| if (m_image->status() == ReleaseVariant::WRITE_VERIFYING) { | ||
|
|
@@ -260,9 +260,6 @@ void LinuxDrive::cancel() | |
| m_image->setStatus(ReleaseVariant::FAILED); | ||
| } | ||
| } | ||
| m_process->kill(); | ||
| m_process->deleteLater(); | ||
| m_process = nullptr; | ||
| beingCancelled = false; | ||
| } | ||
| } | ||
|
|
@@ -271,8 +268,7 @@ void LinuxDrive::restore() | |
| { | ||
| mDebug() << this->metaObject()->className() << "Will now restore" << this->m_device; | ||
|
|
||
| if (!m_process) | ||
| m_process = new QProcess(this); | ||
| m_process.reset(new QProcess(this)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, use |
||
|
|
||
| m_restoreStatus = RESTORING; | ||
| emit restoreStatusChanged(); | ||
|
|
@@ -294,9 +290,9 @@ void LinuxDrive::restore() | |
| mDebug() << this->metaObject()->className() << "Helper command will be" << args; | ||
| m_process->setArguments(args); | ||
|
|
||
| connect(m_process, &QProcess::readyRead, this, &LinuxDrive::onReadyRead); | ||
| connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onRestoreFinished(int, QProcess::ExitStatus))); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process, &QProcess::terminate); | ||
| connect(m_process.get(), &QProcess::readyRead, this, &LinuxDrive::onReadyRead); | ||
| connect(m_process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onRestoreFinished(int, QProcess::ExitStatus))); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process.get(), &QProcess::terminate); | ||
|
|
||
| m_process->start(QIODevice::ReadOnly); | ||
| } | ||
|
|
@@ -353,11 +349,8 @@ void LinuxDrive::onFinished(int exitCode, QProcess::ExitStatus status) | |
| } | ||
| } | ||
|
|
||
| if (m_process) { | ||
| m_process->deleteLater(); | ||
| m_process = nullptr; | ||
| m_image = nullptr; | ||
| } | ||
| m_process.reset(); | ||
| m_image = nullptr; | ||
| } | ||
|
|
||
| void LinuxDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus status) | ||
|
|
@@ -373,10 +366,7 @@ void LinuxDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus status) | |
| } else { | ||
| m_restoreStatus = RESTORED; | ||
| } | ||
| if (m_process) { | ||
| m_process->deleteLater(); | ||
| m_process = nullptr; | ||
| } | ||
| m_process.reset(); | ||
| emit restoreStatusChanged(); | ||
| } | ||
|
|
||
|
|
@@ -389,8 +379,7 @@ void LinuxDrive::onErrorOccurred(QProcess::ProcessError e) | |
| QString errorMessage = m_process->errorString(); | ||
| mWarning() << "Restoring failed:" << errorMessage; | ||
| m_image->setErrorString(errorMessage); | ||
| m_process->deleteLater(); | ||
| m_process = nullptr; | ||
| m_process.reset(); | ||
| m_image->setStatus(ReleaseVariant::FAILED); | ||
| m_image = nullptr; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,8 +76,6 @@ private slots: | |
|
|
||
| private: | ||
| QString m_device; | ||
|
|
||
| QProcess *m_process{nullptr}; | ||
| }; | ||
|
|
||
| #endif // LINUXDRIVEMANAGER_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,19 +87,16 @@ bool MacDrive::write(ReleaseVariant *data) | |
| if (m_image->status() == ReleaseVariant::READY || m_image->status() == ReleaseVariant::FAILED || m_image->status() == ReleaseVariant::FAILED_VERIFICATION || m_image->status() == ReleaseVariant::FINISHED) | ||
| m_image->setStatus(ReleaseVariant::WRITING); | ||
|
|
||
| if (m_child) { | ||
| // TODO some handling of an already present process | ||
| m_child->deleteLater(); | ||
| } | ||
| m_child = new QProcess(this); | ||
| connect(m_child, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onFinished); | ||
| connect(m_child, &QProcess::readyRead, this, &MacDrive::onReadyRead); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_child, &QProcess::terminate); | ||
| // Create new process using unique_ptr | ||
| m_process.reset(new QProcess(this)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| connect(m_process.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onFinished); | ||
| connect(m_process.get(), &QProcess::readyRead, this, &MacDrive::onReadyRead); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process.get(), &QProcess::terminate); | ||
|
|
||
| if (QFile::exists(qApp->applicationDirPath() + "/../../../../helper/mac/helper.app/Contents/MacOS/helper")) { | ||
| m_child->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| } else if (QFile::exists(qApp->applicationDirPath() + "/helper")) { | ||
| m_child->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| } else { | ||
| data->setErrorString(tr("Could not find the helper binary. Check your installation.")); | ||
| setDelayedWrite(false); | ||
|
|
@@ -114,39 +111,32 @@ bool MacDrive::write(ReleaseVariant *data) | |
| } | ||
| args.append(m_bsdDevice); | ||
|
|
||
| mCritical() << "The command is" << m_child->program() << args; | ||
| m_child->setArguments(args); | ||
| mCritical() << "The command is" << m_process->program() << args; | ||
| m_process->setArguments(args); | ||
|
|
||
| m_child->start(); | ||
| m_process->start(); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void MacDrive::cancel() | ||
|
||
| { | ||
| Drive::cancel(); | ||
| if (m_child) { | ||
| m_child->kill(); | ||
| m_child->deleteLater(); | ||
| m_child = nullptr; | ||
| } | ||
| } | ||
|
|
||
| void MacDrive::restore() | ||
| { | ||
| mCritical() << "starting to restore"; | ||
| if (m_child) | ||
| m_child->deleteLater(); | ||
|
|
||
| m_child = new QProcess(this); | ||
| m_process.reset(new QProcess(this)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| m_restoreStatus = RESTORING; | ||
| emit restoreStatusChanged(); | ||
|
|
||
| if (QFile::exists(qApp->applicationDirPath() + "/../../../../helper/mac/helper.app/Contents/MacOS/helper")) { | ||
| m_child->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| } else if (QFile::exists(qApp->applicationDirPath() + "/helper")) { | ||
| m_child->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| } else { | ||
| m_restoreStatus = RESTORE_ERROR; | ||
| return; | ||
|
|
@@ -155,16 +145,16 @@ void MacDrive::restore() | |
| QStringList args; | ||
| args.append("restore"); | ||
| args.append(m_bsdDevice); | ||
| m_child->setArguments(args); | ||
| m_process->setArguments(args); | ||
|
|
||
| m_child->setProcessChannelMode(QProcess::ForwardedChannels); | ||
| m_process->setProcessChannelMode(QProcess::ForwardedChannels); | ||
|
|
||
| connect(m_child, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onRestoreFinished); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_child, &QProcess::terminate); | ||
| connect(m_process.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onRestoreFinished); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process.get(), &QProcess::terminate); | ||
|
|
||
| mCritical() << "The command is" << m_child->program() << args; | ||
| mCritical() << "The command is" << m_process->program() << args; | ||
|
|
||
| m_child->start(); | ||
| m_process->start(); | ||
| } | ||
|
|
||
| void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus) | ||
|
|
@@ -173,11 +163,11 @@ void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus) | |
|
|
||
| setDelayedWrite(false); | ||
|
|
||
| if (!m_child) | ||
| if (!m_process) | ||
| return; | ||
|
|
||
| if (exitCode != 0) { | ||
| QString output = m_child->readAllStandardError(); | ||
| QString output = m_process->readAllStandardError(); | ||
| QRegularExpression re("^.+:.+: "); | ||
| QStringList lines = output.split('\n'); | ||
| if (lines.length() > 0) { | ||
|
|
@@ -194,25 +184,22 @@ void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus) | |
|
|
||
| void MacDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus exitStatus) | ||
| { | ||
| if (!m_child) | ||
| if (!m_process) | ||
| return; | ||
|
|
||
| mCritical() << "Process finished" << exitCode << exitStatus; | ||
| mCritical() << m_child->readAllStandardError(); | ||
| mCritical() << m_process->readAllStandardError(); | ||
|
|
||
| if (exitCode == 0) | ||
| m_restoreStatus = RESTORED; | ||
| else | ||
| m_restoreStatus = RESTORE_ERROR; | ||
| emit restoreStatusChanged(); | ||
|
|
||
| m_child->deleteLater(); | ||
| m_child = nullptr; | ||
| } | ||
|
|
||
| void MacDrive::onReadyRead() | ||
| { | ||
| if (!m_child) | ||
| if (!m_process) | ||
| return; | ||
|
|
||
| if (m_image->status() == ReleaseVariant::WRITING) { | ||
|
|
@@ -223,9 +210,9 @@ void MacDrive::onReadyRead() | |
| if (m_image->status() != ReleaseVariant::WRITE_VERIFYING && m_image->status() != ReleaseVariant::WRITING) | ||
| m_image->setStatus(ReleaseVariant::WRITING); | ||
|
|
||
| while (m_child->bytesAvailable() > 0) { | ||
| while (m_process->bytesAvailable() > 0) { | ||
| bool ok; | ||
| int64_t bytes = m_child->readLine().trimmed().toULongLong(&ok); | ||
| int64_t bytes = m_process->readLine().trimmed().toULongLong(&ok); | ||
| if (ok) | ||
| m_progress->setValue(bytes); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,6 @@ private slots: | |
|
|
||
| private: | ||
| QString m_bsdDevice; | ||
| QProcess *m_child{nullptr}; | ||
| }; | ||
|
|
||
| #endif // MACDRIVEMANAGER_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
→
m_process = std::make_unique<QProcess>(this);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also remove the comment.