From 169a2c24b72052a0b33a5d74df9127afaa7dc605 Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Mon, 15 Nov 2021 13:36:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/backup-daemon.pro | 2 ++ backup-daemon/mybackupmanager.cpp | 13 +++++++--- backup-daemon/mybackupmanager.h | 4 +-- backup-daemon/myprocess/calcbackupsize.h | 2 ++ backup-daemon/mythread.cpp | 8 ++++++ backup-daemon/mythread.h | 17 +++++++++++++ backup-daemon/udisksystembackupproxy.cpp | 32 ++++++++++++++++++++++++ backup-daemon/udisksystembackupproxy.h | 10 ++++++++ backup-daemon/workerfactory.h | 3 ++- kybackup/module/systembackup.cpp | 8 ++++++ 10 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 backup-daemon/mythread.cpp create mode 100644 backup-daemon/mythread.h diff --git a/backup-daemon/backup-daemon.pro b/backup-daemon/backup-daemon.pro index 59310e7..b3b77dc 100755 --- a/backup-daemon/backup-daemon.pro +++ b/backup-daemon/backup-daemon.pro @@ -35,6 +35,7 @@ HEADERS += \ myprocess/calcbackupsize.h \ myprocess/mountbackupprocess.h \ myprocess/rsyncpathtodirprocess.h \ + mythread.h \ parsebackuplist.h \ systembackupproxy.h \ udisksystembackupproxy.h \ @@ -53,6 +54,7 @@ SOURCES += \ myprocess/calcbackupsize.cpp \ myprocess/mountbackupprocess.cpp \ myprocess/rsyncpathtodirprocess.cpp \ + mythread.cpp \ parsebackuplist.cpp \ systembackupproxy.cpp \ udisksystembackupproxy.cpp \ diff --git a/backup-daemon/mybackupmanager.cpp b/backup-daemon/mybackupmanager.cpp index 4581539..0563f5d 100755 --- a/backup-daemon/mybackupmanager.cpp +++ b/backup-daemon/mybackupmanager.cpp @@ -94,8 +94,8 @@ int MyBackupManager::checkEnv(const BackupWrapper& backupWrapper) this->finished(); }); worker->moveToThread(&workerThread); - connect(&workerThread, &QThread::started, worker, &Worker::checkEnv); - connect(&workerThread, &QThread::finished, worker, &Worker::deleteLater); + connect(&workerThread, &MyThread::started, worker, &Worker::checkEnv); + connect(&workerThread, &MyThread::finished, worker, &Worker::deleteLater); workerThread.start(); @@ -136,8 +136,9 @@ int MyBackupManager::goBackup(const BackupWrapper& backupWrapper) this->finished(); }); worker->moveToThread(&workerThread); - connect(&workerThread, &QThread::started, worker, &Worker::doWork); - connect(&workerThread, &QThread::finished, worker, &Worker::deleteLater); + connect(&workerThread, &MyThread::started, worker, &Worker::doWork); + connect(&workerThread, &MyThread::finished, worker, &Worker::deleteLater); + connect(&workerThread, &MyThread::cancelWork, worker, &Worker::cancel); workerThread.start(); @@ -224,6 +225,10 @@ int MyBackupManager::getBackupState(bool& isActive) int MyBackupManager::cancel(const BackupWrapper& backupWrapper) { Q_UNUSED(backupWrapper) + + if (workerThread.isRunning()) + emit workerThread->cancel(); + return 0; } diff --git a/backup-daemon/mybackupmanager.h b/backup-daemon/mybackupmanager.h index b4399af..edd02ca 100755 --- a/backup-daemon/mybackupmanager.h +++ b/backup-daemon/mybackupmanager.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include "mythread.h" #include "../common/mydefine.h" #include "../common/spinlock_mutex.h" @@ -91,7 +91,7 @@ private: bool m_bOpenKysec = false; bool m_bStartKysecDeamon = false; // 工作者线程 - QThread workerThread; + MyThread workerThread; }; #endif // MYBACKUPMANAGER_H diff --git a/backup-daemon/myprocess/calcbackupsize.h b/backup-daemon/myprocess/calcbackupsize.h index 6cc4695..6fdaec6 100755 --- a/backup-daemon/myprocess/calcbackupsize.h +++ b/backup-daemon/myprocess/calcbackupsize.h @@ -23,6 +23,8 @@ public: */ qint64 start(QStringList args, bool block = true); + void stop() { m_process->kill(); } + signals: // 计算结束信号 void finished(qint64 size); diff --git a/backup-daemon/mythread.cpp b/backup-daemon/mythread.cpp new file mode 100644 index 0000000..3f322f7 --- /dev/null +++ b/backup-daemon/mythread.cpp @@ -0,0 +1,8 @@ +#include "mythread.h" + +MyThread::MyThread(QObject *parent) : + QThread(parent) +{} + +MyThread::~MyThread() +{} diff --git a/backup-daemon/mythread.h b/backup-daemon/mythread.h new file mode 100644 index 0000000..25bde27 --- /dev/null +++ b/backup-daemon/mythread.h @@ -0,0 +1,17 @@ +#ifndef MYTHREAD_H +#define MYTHREAD_H + +#include + +class MyThread : public QThread +{ + Q_OBJECT +public: + MyThread(QObject *parent = nullptr); + virtual ~MyThread(); + +signals: + void cancelWork(); +}; + +#endif // MYTHREAD_H diff --git a/backup-daemon/udisksystembackupproxy.cpp b/backup-daemon/udisksystembackupproxy.cpp index 1cf1819..65d7af4 100644 --- a/backup-daemon/udisksystembackupproxy.cpp +++ b/backup-daemon/udisksystembackupproxy.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "../common/utils.h" #include "../common/mydusizetool.h" @@ -44,6 +45,7 @@ bool UDiskSystemBackupProxy::checkEnvEx() return false; } + QTimer::singleShot(1*1000, this, &UDiskSystemBackupProxy::checkDestDirExists); // 2、计算备份大小 calcSizeForBackup(); @@ -345,5 +347,35 @@ void UDiskSystemBackupProxy::do_kylin_security(const QString& dstDir) } } +/** + * @brief 校验移动盘是否还在 + * @return: bool,存在返回true;不存在返回false + * @author: zhaominyong + * @since: 2021/05/24 + * @note: + * add by zhaominyong at 2021/05/24 for bug:54377 【备份还原】备份数据到U盘的过程中拔出U盘,备份还原工具仍然一直显示正在备份数据 + */ +bool UDiskSystemBackupProxy::checkDestDirExists() +{ + QDir dir(m_backupWrapper.m_prefixDestPath); + if (!dir.exists()) { + qCritical() << QString("dstDir %s is not exist!").arg(m_backupWrapper.m_prefixDestPath); + + if (m_calc) + m_calc->stop(); + if (m_p) + m_p->stop(); + + return false; + } + + if (!m_bSuccess) + { + QTimer::singleShot(1*1000, this, &UDiskSystemBackupProxy::checkDestDirExists); + } + + return true; +} + diff --git a/backup-daemon/udisksystembackupproxy.h b/backup-daemon/udisksystembackupproxy.h index 9a8d9c2..13c5193 100644 --- a/backup-daemon/udisksystembackupproxy.h +++ b/backup-daemon/udisksystembackupproxy.h @@ -66,6 +66,16 @@ private: void do_kylin_security(const QString& dstDir); + /** + * @brief 校验移动盘是否还在 + * @return: bool,存在返回true;不存在返回false + * @author: zhaominyong + * @since: 2021/05/24 + * @note: + * add by zhaominyong at 2021/05/24 for bug:54377 【备份还原】备份数据到U盘的过程中拔出U盘,备份还原工具仍然一直显示正在备份数据 + */ + bool checkDestDirExists(); + // 计算备份空间大小的进程 CalcBackupSize *m_calc; diff --git a/backup-daemon/workerfactory.h b/backup-daemon/workerfactory.h index c554a84..ed18545 100755 --- a/backup-daemon/workerfactory.h +++ b/backup-daemon/workerfactory.h @@ -46,7 +46,8 @@ protected: public: void setParam(const BackupWrapper& backupWrapper) { m_backupWrapper = backupWrapper; } -protected: +public: + // 同一时间只能运行一个备份/还原等操作 BackupWrapper m_backupWrapper; }; diff --git a/kybackup/module/systembackup.cpp b/kybackup/module/systembackup.cpp index 361642d..dcc6271 100644 --- a/kybackup/module/systembackup.cpp +++ b/kybackup/module/systembackup.cpp @@ -669,6 +669,13 @@ void SystemBackup::initFifthWidget() MyLabel *label4 = new MyLabel(tr("finished"), fifth); label4->setGeometry(551, 72, 164, 30); + // 检测等待图标 + QLabel *loadingGif = new QLabel(fifth); + // 环境检测等待动画 + QMovie *movie = new QMovie(":/images/loading.gif", QByteArray(), fifth); + loadingGif->setMovie(movie); + loadingGif->setGeometry(260, 190, 20, 20); + // 进度条 RingsProgressbar *progressBar = new RingsProgressbar(fifth); progressBar->setGeometry(301, 151, 100, 100); @@ -689,6 +696,7 @@ void SystemBackup::initFifthWidget() // 开始备份 connect(this, &SystemBackup::startBackup, this, [=] { progressBar->setPersent(0); + movie->start(); // 开始备份 this->on_backup_start();