diff --git a/backup-daemon/udiskdatabackupproxy.cpp b/backup-daemon/udiskdatabackupproxy.cpp index f7e8c38..ce171c6 100755 --- a/backup-daemon/udiskdatabackupproxy.cpp +++ b/backup-daemon/udiskdatabackupproxy.cpp @@ -13,6 +13,7 @@ IMPLEMENT_DYNCREATE(UDiskDataBackupProxy) UDiskDataBackupProxy::UDiskDataBackupProxy() { + m_isForce = false; } UDiskDataBackupProxy::~UDiskDataBackupProxy() @@ -132,6 +133,12 @@ bool UDiskDataBackupProxy::checkFreeCapacityToUdisk(qint64 itotalSize) if (m_bCancel) return false; + // 拔掉U盘的场景 + if (m_isForce) { + emit this->checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); + return false; + } + // 1、计算待备份数据的大小 m_size = itotalSize; // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留500M的空间 @@ -388,12 +395,15 @@ bool UDiskDataBackupProxy::checkDestDirExists() return false; } - if (Utils::isDirEmpty(m_backupWrapper.m_prefixDestPath) && m_p != nullptr) { + if (Utils::isDirEmpty(m_backupWrapper.m_prefixDestPath)) { qCritical() << QString("dstDir %s is not exist!").arg(m_backupWrapper.m_prefixDestPath); - m_p->stop(); + m_isForce = true; + if (m_calc != nullptr) + m_calc->stop(); + if (m_p != nullptr) + m_p->stop(); // 10s钟后如果还没有退出,则强制退出 QTimer::singleShot(10*1000, this, &UDiskDataBackupProxy::checkDestDirExists); - m_isForce = true; } else { QTimer::singleShot(1*1000, this, &UDiskDataBackupProxy::checkDestDirExists); } diff --git a/backup-daemon/udiskdatarestoreproxy.cpp b/backup-daemon/udiskdatarestoreproxy.cpp index 4093a3f..5b2ef2e 100755 --- a/backup-daemon/udiskdatarestoreproxy.cpp +++ b/backup-daemon/udiskdatarestoreproxy.cpp @@ -166,8 +166,9 @@ bool UDiskDataRestoreProxy::checkUdiskExists() return false; } - if (Utils::isDirEmpty(m_backupPath) && m_p != nullptr) { - m_p->stop(); + if (Utils::isDirEmpty(m_backupPath)) { + if (m_p != nullptr) + m_p->stop(); // 10s钟后如果还没有退出,则强制退出 QTimer::singleShot(10*1000, this, &UDiskDataRestoreProxy::checkUdiskExists); m_isForce = true; diff --git a/backup-daemon/udiskghostImageproxy.cpp b/backup-daemon/udiskghostImageproxy.cpp index 8e73273..11bf2c9 100755 --- a/backup-daemon/udiskghostImageproxy.cpp +++ b/backup-daemon/udiskghostImageproxy.cpp @@ -193,7 +193,7 @@ void UDiskGhostImageProxy::doGhostImage() if (m_bCancel) return ; - if (result) { + if (result && !m_isForce) { chown(m_kyimg.toLocal8Bit().data(), m_backupWrapper.m_frontUid, m_backupWrapper.m_gid); // 同步到U盘 @@ -262,9 +262,12 @@ bool UDiskGhostImageProxy::checkDestDirExists() return false; } - if (Utils::isDirEmpty(m_backupWrapper.m_prefixDestPath) && m_p != nullptr) { + if (Utils::isDirEmpty(m_backupWrapper.m_prefixDestPath)) { qCritical() << QString("dstDir %s is not exist!").arg(m_backupWrapper.m_prefixDestPath); - m_p->stop(); + if (m_mksquashfs) + m_mksquashfs->stop(); + if (m_p) + m_p->stop(); // 10s钟后如果还没有退出,则强制退出 QTimer::singleShot(10*1000, this, &UDiskGhostImageProxy::checkDestDirExists); m_isForce = true; diff --git a/backup-daemon/udisksystembackupproxy.cpp b/backup-daemon/udisksystembackupproxy.cpp index bf45e95..03e5570 100755 --- a/backup-daemon/udisksystembackupproxy.cpp +++ b/backup-daemon/udisksystembackupproxy.cpp @@ -179,6 +179,12 @@ void UDiskSystemBackupProxy::checkFreeCapacity(qint64 itotalSize) if (m_bCancel) return ; + // 拔掉U盘的场景 + if (m_isForce) { + emit this->checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); + return false; + } + // 1、计算待备份数据的大小 m_size = itotalSize; // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留500M的空间 @@ -318,7 +324,7 @@ void UDiskSystemBackupProxy::doMksqushfs() if (m_bCancel) return ; - if (result) { + if (result && !m_isForce) { // 开始备份 doBackup(); } else { @@ -575,12 +581,17 @@ bool UDiskSystemBackupProxy::checkDestDirExists() return false; } - if (Utils::isDirEmpty(m_backupWrapper.m_prefixDestPath) && m_p != nullptr) { + if (Utils::isDirEmpty(m_backupWrapper.m_prefixDestPath)) { qCritical() << QString("dstDir %s is not exist!").arg(m_backupWrapper.m_prefixDestPath); - m_p->stop(); + m_isForce = true; + if (m_calc != nullptr) + m_calc->stop(); + if (m_mksquashfs != nullptr) + m_mksquashfs->stop(); + if (m_p != nullptr) + m_p->stop(); // 10s钟后如果还没有退出,则强制退出 QTimer::singleShot(10*1000, this, &UDiskSystemBackupProxy::checkDestDirExists); - m_isForce = true; } else { QTimer::singleShot(1*1000, this, &UDiskSystemBackupProxy::checkDestDirExists); } diff --git a/backup-daemon/udisksystemrestoreproxy.cpp b/backup-daemon/udisksystemrestoreproxy.cpp index 5b3836e..739425a 100755 --- a/backup-daemon/udisksystemrestoreproxy.cpp +++ b/backup-daemon/udisksystemrestoreproxy.cpp @@ -358,6 +358,13 @@ bool UDiskSystemRestoreProxy::doPrepare() */ void UDiskSystemRestoreProxy::restoreSystem() { + // 理论上开始不会走下面这个U盘拔出的校验 + if (m_isForce) { + qCritical("U盘已拔出"); + emit checkResult(int(BackupResult::INC_NOT_FOUND_DIR)); + return false; + } + // 停止安全防护, 迁移到业务开始的锁定中去 // QProcess::execute("systemctl stop kysec-init.service"); @@ -462,15 +469,18 @@ bool UDiskSystemRestoreProxy::checkUdiskExists() if (!m_isFinished) { // 拔掉U盘后,没有响应的场景(怀疑可能是某应用程序关闭引起,希望不是dbus服务关掉了) if (m_isForce) { + qCritical() << QString("强制退出"); emit this->workResult(false); return false; } - if (Utils::isDirEmpty(m_backupPath) && m_p != nullptr) { - m_p->stop(); + if (Utils::isDirEmpty(m_backupPath)) { + qCritical() << QString("srcDir %s is not exist!").arg(m_backupPath); + m_isForce = true; + if (m_p != nullptr) + m_p->stop(); // 10s钟后如果还没有退出,则强制退出 QTimer::singleShot(10*1000, this, &UDiskSystemRestoreProxy::checkUdiskExists); - m_isForce = true; } else { QTimer::singleShot(1*1000, this, &UDiskSystemRestoreProxy::checkUdiskExists); }