应系统更新模块要求,提供给其系统还原接口

This commit is contained in:
赵民勇 2023-03-20 18:37:26 +08:00
parent 631d53f340
commit 781f0a9e5d
5 changed files with 99 additions and 19 deletions

View File

@ -49,10 +49,16 @@ bool ManagerAdaptor::umountBackupPartition()
return out0;
}
void ManagerAdaptor::autoBackUpForSystemUpdate_noreturn(const QString &autobackup_name, const QString &create_note, const QString &inc_note, const QString &frontUserName, int frontUid)
void ManagerAdaptor::autoBackUpForSystemUpdate_noreturn(const QString &backupName, const QString &createNote, const QString &incNote, const QString &frontUserName, int frontUid)
{
// handle method call com.kylin.backup.manager.autoBackUpForSystemUpdate_noreturn
QMetaObject::invokeMethod(parent(), "autoBackUpForSystemUpdate_noreturn", Q_ARG(QString, autobackup_name), Q_ARG(QString, create_note), Q_ARG(QString, inc_note), Q_ARG(QString, frontUserName), Q_ARG(int, frontUid));
QMetaObject::invokeMethod(parent(), "autoBackUpForSystemUpdate_noreturn", Q_ARG(QString, backupName), Q_ARG(QString, createNote), Q_ARG(QString, incNote), Q_ARG(QString, frontUserName), Q_ARG(int, frontUid));
}
void ManagerAdaptor::autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid)
{
// handle method call com.kylin.backup.manager.autoRestoreForSystemUpdate
QMetaObject::invokeMethod(parent(), "autoRestoreForSystemUpdate", Q_ARG(QString, frontUserName), Q_ARG(int, frontUid));
}
int ManagerAdaptor::checkEnv(BackupWrapper backupWrapper)

View File

@ -58,6 +58,9 @@ class ManagerAdaptor: public QDBusAbstractAdaptor
" <signal name=\"backupFinished\">\n"
" <arg direction=\"out\" type=\"b\" name=\"result\"/>\n"
" </signal>\n"
" <signal name=\"sendAutoRestoreResult\">\n"
" <arg direction=\"out\" type=\"b\" name=\"result\"/>\n"
" </signal>\n"
" <signal name=\"progress\">\n"
" <arg direction=\"out\" type=\"i\"/>\n"
" <arg direction=\"out\" type=\"i\"/>\n"
@ -69,9 +72,13 @@ class ManagerAdaptor: public QDBusAbstractAdaptor
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"autoBackUpForSystemUpdate_noreturn\">\n"
" <arg direction=\"in\" type=\"s\" name=\"autobackup_name\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"create_note\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"inc_note\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"backupName\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"createNote\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"incNote\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"frontUserName\"/>\n"
" <arg direction=\"in\" type=\"i\" name=\"frontUid\"/>\n"
" </method>\n"
" <method name=\"autoRestoreForSystemUpdate\">\n"
" <arg direction=\"in\" type=\"s\" name=\"frontUserName\"/>\n"
" <arg direction=\"in\" type=\"i\" name=\"frontUid\"/>\n"
" </method>\n"
@ -121,7 +128,8 @@ public: // PROPERTIES
public Q_SLOTS: // METHODS
int Mount_backup_partition();
bool umountBackupPartition();
void autoBackUpForSystemUpdate_noreturn(const QString &autobackup_name, const QString &create_note, const QString &inc_note, const QString &frontUserName, int frontUid);
void autoBackUpForSystemUpdate_noreturn(const QString &backupName, const QString &createNote, const QString &incNote, const QString &frontUserName, int frontUid);
void autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid);
int checkEnv(BackupWrapper backupWrapper);
int deleteBackupPoint(BackupWrapper backupWrapper);
QString getBackupCommentForSystemUpdate(QString &state);
@ -141,6 +149,7 @@ Q_SIGNALS: // SIGNALS
void sendRate(int in0, int in1);
void sendRestoreResult(bool result);
void sendStartBackupResult(int result);
void sendAutoRestoreResult(bool result);
};
#endif

View File

@ -300,13 +300,13 @@ int MyBackupManager::ghostBackup(const BackupWrapper& backupWrapper)
/**
* @brief
* @param autobackup_name
* @param create_note
* @param inc_note
* @param backupName
* @param createNote
* @param incNote
* @param frontUserName
* @param frontUid id
*/
void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid)
void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& backupName, const QString& createNote, const QString& incNote, const QString& frontUserName, int frontUid)
{
qDebug("MyBackupManager::autoBackUpForSystemUpdate_noreturn invoke begin");
@ -321,13 +321,13 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
xmlPath.replace("//", "/");
ParseBackupList parseXml(xmlPath);
ParseBackupList::BackupPoint backupPoint = parseXml.findBackupPointByUuid(backupWrapper.m_uuid);
if (autobackup_name.isEmpty()) {
if (backupName.isEmpty()) {
if (backupPoint.m_backupName.isEmpty())
backupWrapper.m_backupName = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
else
backupWrapper.m_backupName = backupPoint.m_backupName;
} else {
backupWrapper.m_backupName = autobackup_name;
backupWrapper.m_backupName = backupName;
}
backupWrapper.m_backupPaths << "/";
backupWrapper.m_backupExcludePaths = Utils::getFromExcludePathsFile();
@ -339,7 +339,7 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
backupWrapper.m_iPosition = BackupPosition::LOCAL;
backupWrapper.m_frontUserName = frontUserName;
backupWrapper.m_frontUid = frontUid;
backupWrapper.m_note = create_note.isEmpty() ? inc_note : create_note;
backupWrapper.m_note = createNote.isEmpty() ? incNote : createNote;
Worker* worker = WorkerFactory::createWorker(backupWrapper.m_type, backupWrapper.m_iPosition);
if (nullptr == worker) {
@ -357,7 +357,7 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
default:
emit this->sendStartBackupResult(result);
this->finished();
if (!Utils::isRunning("kybackup")) {
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
this->umountBackupPartition();
}
break;
@ -369,7 +369,7 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
connect(worker, &Worker::workResult, this, [&] (bool result) {
emit this->sendBackupResult(result);
this->finished();
if (!Utils::isRunning("kybackup")) {
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
this->umountBackupPartition();
}
});
@ -382,6 +382,66 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
qDebug("MyBackupManager::autoBackUpForSystemUpdate_noreturn invoke end");
}
/**
* @brief
* @note
*/
void MyBackupManager::autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid)
{
qDebug("MyBackupManager::autoRestoreForSystemUpdate invoke begin");
if (m_isActive || !lock(frontUid)) {
emit sendAutoRestoreResult(false);
return ;
}
Mount_backup_partition();
BackupWrapper backupWrapper;
backupWrapper.m_uuid = AUTO_BACKUP_UUID;
backupWrapper.m_type = BackupType::RESTORE_SYSTEM;
backupWrapper.m_iPosition = BackupPosition::LOCAL;
backupWrapper.m_frontUserName = frontUserName;
backupWrapper.m_frontUid = frontUid;
Worker* worker = WorkerFactory::createWorker(backupWrapper.m_type, backupWrapper.m_iPosition);
if (nullptr == worker) {
emit sendAutoRestoreResult(false);
return ;
}
worker->setParam(backupWrapper);
connect(worker, &Worker::checkResult, this, [&](int result) {
switch (result) {
case int(BackupResult::CHECK_ENV_SUCCESS) :
case int(BackupResult::RESTORE_START_SUCCESS) :
break;
default:
emit this->sendAutoRestoreResult(false);
this->finished();
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
this->umountBackupPartition();
}
break;
}
});
connect(worker, &Worker::progress, this, [&](int rate) {
emit this->sendRate(int(BackupState::WORKING), rate);
});
connect(worker, &Worker::workResult, this, [&] (bool result) {
emit this->sendAutoRestoreResult(result);
this->finished();
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
this->umountBackupPartition();
}
});
worker->moveToThread(&workerThread);
connect(&workerThread, &MyThread::started, worker, &Worker::doWork);
connect(&workerThread, &MyThread::finished, worker, &Worker::deleteLater);
workerThread.start();
qDebug("MyBackupManager::autoRestoreForSystemUpdate invoke end");
}
/**
* @brief
* @param state

View File

@ -25,6 +25,8 @@ signals:
void sendBackupResult(bool result);
// 进度信号
void sendRate(int, int);
// 还原结果信号
void sendAutoRestoreResult(bool result);
// 模块内使用的信号
// 进度信号
@ -56,7 +58,9 @@ public slots:
// ghost镜像
int ghostBackup(const BackupWrapper& backupWrapper);
// 控制面板调用的备份接口,重构暂时先兼容以前的老接口
void autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid);
void autoBackUpForSystemUpdate_noreturn(const QString& backupName, const QString& createNote, const QString& incNote, const QString& frontUserName, int frontUid);
// 控制面板调用的系统自动备份点还原接口
void autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid);
// 控制面板调用的获取系统备份接口
QString getBackupCommentForSystemUpdate(QString& state);
// 获取备份状态
@ -79,13 +83,13 @@ private:
// 解锁
bool unlock();
void uninhibit();
// 自旋锁
spinlock_mutex m_mutex;
// 关闭、开启安全保护
void setKysecStatus(bool status);
private:
// 自旋锁
spinlock_mutex m_mutex;
// 锁文件描述符
int m_fdLockFile = -1;
QDBusUnixFileDescriptor m_inhibitFileDescriptor;

View File

@ -307,6 +307,7 @@ void ParseBackupList::getCustomizePaths(QStringList &customizePaths)
/**
* @brief
* @return
* @note
*/
ParseBackupList::BackupPoint ParseBackupList::getLastSysBackupPoint()
{
@ -328,7 +329,7 @@ ParseBackupList::BackupPoint ParseBackupList::getLastSysBackupPoint()
continue;
QDomElement eleUuid = node.firstChildElement(UUID);
if (eleUuid.isNull() || eleUuid.text() == AUTO_BACKUP_UUID)
if (eleUuid.isNull() || eleUuid.text() == AUTO_BACKUP_UUID || eleUuid.text() == FACTORY_BACKUP_UUID)
continue;
QDomElement eleState = node.firstChildElement(STATE);