阶段提交

This commit is contained in:
zhaominyong 2021-11-15 13:36:00 +08:00
parent 2b1f31aef0
commit 169a2c24b7
10 changed files with 92 additions and 7 deletions

View File

@ -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 \

View File

@ -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;
}

View File

@ -4,7 +4,7 @@
#include <QObject>
#include <QtDBus/QDBusVariant>
#include <QHash>
#include <QThread>
#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

View File

@ -23,6 +23,8 @@ public:
*/
qint64 start(QStringList args, bool block = true);
void stop() { m_process->kill(); }
signals:
// 计算结束信号
void finished(qint64 size);

View File

@ -0,0 +1,8 @@
#include "mythread.h"
MyThread::MyThread(QObject *parent) :
QThread(parent)
{}
MyThread::~MyThread()
{}

17
backup-daemon/mythread.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(QObject *parent = nullptr);
virtual ~MyThread();
signals:
void cancelWork();
};
#endif // MYTHREAD_H

View File

@ -4,6 +4,7 @@
#include <QStorageInfo>
#include <QDateTime>
#include <QDebug>
#include <QTimer>
#include <kysec/status.h>
#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,truefalse
* @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;
}

View File

@ -66,6 +66,16 @@ private:
void do_kylin_security(const QString& dstDir);
/**
* @brief
* @return: bool,truefalse
* @author: zhaominyong
* @since: 2021/05/24
* @note:
* add by zhaominyong at 2021/05/24 for bug:54377 U盘的过程中拔出U盘
*/
bool checkDestDirExists();
// 计算备份空间大小的进程
CalcBackupSize *m_calc;

View File

@ -46,7 +46,8 @@ protected:
public:
void setParam(const BackupWrapper& backupWrapper) { m_backupWrapper = backupWrapper; }
protected:
public:
// 同一时间只能运行一个备份/还原等操作
BackupWrapper m_backupWrapper;
};

View File

@ -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();