diff --git a/backup-daemon/udiskdatarestoreproxy.cpp b/backup-daemon/udiskdatarestoreproxy.cpp index df00450..4447af7 100755 --- a/backup-daemon/udiskdatarestoreproxy.cpp +++ b/backup-daemon/udiskdatarestoreproxy.cpp @@ -18,6 +18,7 @@ UDiskDataRestoreProxy::UDiskDataRestoreProxy() m_bSuccess = false; m_isFinished = false; m_p = nullptr; + m_isForce = false; } /** @@ -136,6 +137,7 @@ void UDiskDataRestoreProxy::restoreData() m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::progress, this, &UDiskDataRestoreProxy::progress); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { + m_isForce = false; m_bSuccess = result; m_isFinished = true; if (result) { @@ -158,10 +160,19 @@ void UDiskDataRestoreProxy::restoreData() bool UDiskDataRestoreProxy::checkUdiskExists() { if (!m_isFinished) { - if (Utils::isDirEmpty(m_backupPath) && m_p != nullptr) + // 拔掉U盘后,没有响应的场景(怀疑可能是某应用程序关闭引起,希望不是dbus服务关掉了) + if (m_isForce) { + emit this->workResult(false); + } + + if (Utils::isDirEmpty(m_backupPath) && m_p != nullptr) { m_p->stop(); - else + // 10s钟后如果还没有退出,则强制退出 + QTimer::singleShot(10*1000, this, &UDiskDataRestoreProxy::checkUdiskExists); + m_isForce = true; + } else { QTimer::singleShot(1*1000, this, &UDiskDataRestoreProxy::checkUdiskExists); + } } return true; diff --git a/backup-daemon/udiskdatarestoreproxy.h b/backup-daemon/udiskdatarestoreproxy.h index bca65e9..c939fff 100755 --- a/backup-daemon/udiskdatarestoreproxy.h +++ b/backup-daemon/udiskdatarestoreproxy.h @@ -56,7 +56,8 @@ private: RsyncPathToDirProcess *m_p; // 当前备份节点 ParseBackupList::BackupPoint m_backupPoint; - + // 强制结束标志(stop后没反应的情况,系统处于睡眠状态) + bool m_isForce; }; #endif // UDISKDATARESTOREPROXY_H diff --git a/backup-daemon/udisksystemrestoreproxy.cpp b/backup-daemon/udisksystemrestoreproxy.cpp index 61a5428..a2040bd 100755 --- a/backup-daemon/udisksystemrestoreproxy.cpp +++ b/backup-daemon/udisksystemrestoreproxy.cpp @@ -18,6 +18,7 @@ UDiskSystemRestoreProxy::UDiskSystemRestoreProxy() { m_isFinished = false; m_p = nullptr; + m_isForce = false; } /** @@ -378,6 +379,7 @@ void UDiskSystemRestoreProxy::restoreSystem() m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::progress, this, &UDiskSystemRestoreProxy::progress); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { + m_isForce = false; if (result) { QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"); // Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)); @@ -451,7 +453,6 @@ void UDiskSystemRestoreProxy::updateGrubUUid() } } - /** * @brief 监控移动设备是否还在 * @return true-在;false-不在 @@ -459,10 +460,19 @@ void UDiskSystemRestoreProxy::updateGrubUUid() bool UDiskSystemRestoreProxy::checkUdiskExists() { if (!m_isFinished) { - if (Utils::isDirEmpty(m_backupPath) && m_p != nullptr) + // 拔掉U盘后,没有响应的场景(怀疑可能是某应用程序关闭引起,希望不是dbus服务关掉了) + if (m_isForce) { + emit this->workResult(false); + } + + if (Utils::isDirEmpty(m_backupPath) && m_p != nullptr) { m_p->stop(); - else + // 10s钟后如果还没有退出,则强制退出 + QTimer::singleShot(10*1000, this, &UDiskSystemRestoreProxy::checkUdiskExists); + m_isForce = true; + } else { QTimer::singleShot(1*1000, this, &UDiskSystemRestoreProxy::checkUdiskExists); + } } return true; diff --git a/backup-daemon/udisksystemrestoreproxy.h b/backup-daemon/udisksystemrestoreproxy.h index db83295..3b7f058 100755 --- a/backup-daemon/udisksystemrestoreproxy.h +++ b/backup-daemon/udisksystemrestoreproxy.h @@ -72,6 +72,8 @@ private: RsyncPathToDirProcess *m_p; // 当前备份节点 ParseBackupList::BackupPoint m_backupPoint; + // 强制结束标志(stop后没反应的情况,系统处于睡眠状态) + bool m_isForce; }; #endif // UDISKSYSTEMRESTOREPROXY_H