From f555fe5c20941c8be700e721290883592c2e0872 Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Wed, 1 Sep 2021 15:46:24 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/main.cpp | 1 + .../myprocess/rsyncpathtodirprocess.cpp | 1 + backup-daemon/parsebackuplist.cpp | 41 ++++++++++++++++++- backup-daemon/parsebackuplist.h | 7 ++++ backup-daemon/systembackupproxy.cpp | 1 + 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/backup-daemon/main.cpp b/backup-daemon/main.cpp index bbd0516..717413c 100755 --- a/backup-daemon/main.cpp +++ b/backup-daemon/main.cpp @@ -31,6 +31,7 @@ int main(int argc, char *argv[]) qDebug() << QString("测试 begin"); BackupWrapper backupWrapper; backupWrapper.m_backupName = "赵民勇test"; + backupWrapper.m_backupPaths << "/"; backupWrapper.m_backupExcludePaths = Utils::getFromExcludePathsFile(); MyBackupManager manager; manager.goBackup(backupWrapper); diff --git a/backup-daemon/myprocess/rsyncpathtodirprocess.cpp b/backup-daemon/myprocess/rsyncpathtodirprocess.cpp index 3f157b5..354563e 100755 --- a/backup-daemon/myprocess/rsyncpathtodirprocess.cpp +++ b/backup-daemon/myprocess/rsyncpathtodirprocess.cpp @@ -80,6 +80,7 @@ void RsyncPathToDirProcess::processFinished(int exitCode, QProcess::ExitStatus) if (exitCode == QProcess::NormalExit || exitCode == 24 || exitCode == 23) { sync(); m_bSuccess = true; + emit progress(100); emit finished(true); } else { emit finished(false); diff --git a/backup-daemon/parsebackuplist.cpp b/backup-daemon/parsebackuplist.cpp index e21f4fd..90584a0 100755 --- a/backup-daemon/parsebackuplist.cpp +++ b/backup-daemon/parsebackuplist.cpp @@ -385,7 +385,46 @@ ParseBackupList::ParseResult ParseBackupList::updateItem(const BackupPoint & bac } QFile xmlFile(m_xmlPath); - if (!xmlFile.open(QIODevice::WriteOnly)) { + if (!xmlFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + return FAIL; + } + + QTextStream out(&xmlFile); + doc.save(out, QDomNode::NodeType::EntityReferenceNode); + xmlFile.close(); + return SUCCESS; +} + +/** + * @brief 删除备份点记录 + * @param uuid + * @return SUCCESS成功; XML_PARSE_ERR失败 + */ +ParseBackupList::ParseResult ParseBackupList::deleteItem(const QString& uuid) +{ + QDomDocument doc; + if (!Doc_setContent(doc)) + return XML_PARSE_ERR; + + QDomElement root = doc.documentElement(); + QDomNodeList list = root.childNodes(); + + for (int i = 0; i < list.count(); i++) { + QDomNode node = list.at(i); + if (!node.isElement()) + continue; + + QDomElement eleUuid = node.firstChildElement(UUID); + if (eleUuid.isNull() || uuid != eleUuid.text()) + continue; + + root.removeChild(node); + + break ; + } + + QFile xmlFile(m_xmlPath); + if (!xmlFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { return FAIL; } diff --git a/backup-daemon/parsebackuplist.h b/backup-daemon/parsebackuplist.h index 53a77be..12571a3 100755 --- a/backup-daemon/parsebackuplist.h +++ b/backup-daemon/parsebackuplist.h @@ -81,6 +81,13 @@ public: */ ParseResult updateItem(const BackupPoint & backupPoint); + /** + * @brief 删除备份点记录 + * @param uuid + * @return SUCCESS成功; XML_PARSE_ERR失败 + */ + ParseResult deleteItem(const QString& uuid); + inline QString getXmlPath() { return m_xmlPath; } private: diff --git a/backup-daemon/systembackupproxy.cpp b/backup-daemon/systembackupproxy.cpp index 43d5fc6..606a392 100755 --- a/backup-daemon/systembackupproxy.cpp +++ b/backup-daemon/systembackupproxy.cpp @@ -88,6 +88,7 @@ bool SystemBackupProxy::isIncBackup() if (Utils::isDirExist(backupPath)) { m_backupWrapper.m_baseUuid = point.m_uuid; m_backupWrapper.m_bIncrement = true; + m_backupWrapper.m_type = BackupType::INC_BACKUP_SYSTEM; return true; } return false;