Skip to content
Open
12 changes: 12 additions & 0 deletions src/app/drivemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ void DriveManager::onDriveConnected(Drive *d)
endInsertRows();
emit drivesChanged();

// Fix for issue #825: Only change selection if the currently selected drive is not busy
if (selected() && selected()->isBusy()) {
return;
}

// Standard logic: Select the new drive if not busy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comment can be removed

if (m_provider->initialized()) {
m_selectedIndex = position;
emit selectedChanged();
Expand Down Expand Up @@ -289,6 +295,11 @@ bool Drive::delayedWrite() const
return m_delayedWrite;
}

bool Drive::isBusy() const
{
return m_isBusy;
}

void Drive::setDelayedWrite(const bool &o)
{
if (m_delayedWrite != o) {
Expand Down Expand Up @@ -329,6 +340,7 @@ void Drive::cancel()
m_error = QString();
m_restoreStatus = CLEAN;
emit restoreStatusChanged();
m_isBusy = false;
}

bool Drive::operator==(const Drive &o) const
Expand Down
2 changes: 2 additions & 0 deletions src/app/drivemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class Drive : public QObject
virtual qreal size() const;
virtual RestoreStatus restoreStatus();
virtual bool delayedWrite() const;
virtual bool isBusy() const;

virtual void setDelayedWrite(const bool &o);

Expand All @@ -194,6 +195,7 @@ public slots:
RestoreStatus m_restoreStatus{CLEAN};
QString m_error{};
bool m_delayedWrite{false};
bool m_isBusy{false};
};

#endif // DRIVEMANAGER_H
7 changes: 7 additions & 0 deletions src/app/linuxdrivemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +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);

m_isBusy = true; // Set busy state

if (!m_process)
m_process = new QProcess(this);

Expand Down Expand Up @@ -271,6 +273,8 @@ void LinuxDrive::restore()
{
mDebug() << this->metaObject()->className() << "Will now restore" << this->m_device;

m_isBusy = true; // Set busy state

if (!m_process)
m_process = new QProcess(this);

Expand Down Expand Up @@ -339,6 +343,7 @@ void LinuxDrive::onFinished(int exitCode, QProcess::ExitStatus status)
mDebug() << this->metaObject()->className() << "Helper process finished with status" << status;

setDelayedWrite(false);
m_isBusy = false; // Operation complete

if (!m_process)
return;
Expand All @@ -364,6 +369,8 @@ void LinuxDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus status)
{
mDebug() << this->metaObject()->className() << "Helper process finished with status" << status;

m_isBusy = false; // Operation complete

if (exitCode != 0) {
if (m_process)
mWarning() << "Drive restoration failed:" << m_process->readAllStandardError();
Expand Down
7 changes: 7 additions & 0 deletions src/app/macdrivemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ 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);

m_isBusy = true; // Set busy state

if (m_child) {
// TODO some handling of an already present process
m_child->deleteLater();
Expand Down Expand Up @@ -138,6 +140,8 @@ void MacDrive::restore()
if (m_child)
m_child->deleteLater();

m_isBusy = true; // Set busy state

m_child = new QProcess(this);

m_restoreStatus = RESTORING;
Expand Down Expand Up @@ -172,6 +176,7 @@ void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
Q_UNUSED(exitStatus)

setDelayedWrite(false);
m_isBusy = false; // Operation complete

if (!m_child)
return;
Expand All @@ -197,6 +202,8 @@ void MacDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus exitStatus)
if (!m_child)
return;

m_isBusy = false; // Operation complete

mCritical() << "Process finished" << exitCode << exitStatus;
mCritical() << m_child->readAllStandardError();

Expand Down
7 changes: 7 additions & 0 deletions src/app/windrivemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ bool WinDrive::write(ReleaseVariant *data)
if (!Drive::write(data))
return false;

m_isBusy = true; // Set busy state

if (m_child) {
// TODO some handling of an already present process
m_child->deleteLater();
Expand Down Expand Up @@ -181,6 +183,8 @@ void WinDrive::restore()
if (m_child)
m_child->deleteLater();

m_isBusy = true; // Set busy state

m_child = new QProcess(this);

m_restoreStatus = RESTORING;
Expand Down Expand Up @@ -227,6 +231,7 @@ bool WinDrive::operator==(const WinDrive &o) const
void WinDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
setDelayedWrite(false);
m_isBusy = false; // Operation complete

if (!m_child)
return;
Expand Down Expand Up @@ -255,6 +260,8 @@ void WinDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus exitStatus)
return;
}

m_isBusy = false; // Operation complete

mCritical() << "Process finished" << exitCode << exitStatus;
mCritical() << m_child->readAllStandardError();

Expand Down