yhkylin-backup-tools/backup-daemon/deletebackupproxy.cpp

71 lines
1.8 KiB
C++

#include "deletebackupproxy.h"
#include <QProcess>
#include <QDebug>
#include "../common/utils.h"
IMPLEMENT_DYNCREATE(DeleteBackupProxy)
DeleteBackupProxy::DeleteBackupProxy()
{}
DeleteBackupProxy::~DeleteBackupProxy()
{}
void DeleteBackupProxy::doWorkEx()
{
// 1、删除/backup/snapshots/backuplist.xml对应项
if (!deleteXmlBackupPoint())
return;
// 2、删除/backup/snapshots/{uuid}对应目录
deleteBackupPointDir();
// 3、同时删除唯一识别文件中对应的条目
Utils::deleteBackupUniqueRecord(m_backupWrapper.m_backupName);
// 删除成功信号
emit workResult(true);
}
/**
* @brief 删除/backup/snapshots/backuplist.xml对应项
*/
bool DeleteBackupProxy::deleteXmlBackupPoint()
{
QString xmlPath;
if (m_backupWrapper.m_iPosition == BackupPosition::LOCAL)
xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH;
else
xmlPath = m_backupWrapper.m_prefixDestPath + BACKUP_XML_PATH;
xmlPath.replace("//", "/");
ParseBackupList parse(xmlPath);
if (parse.deleteItem(m_backupWrapper.m_uuid) != ParseBackupList::SUCCESS) {
qCritical() << QString("failed to delete %1 from backuplist.xml!").arg(m_backupWrapper.m_uuid);
emit workResult(false);
return false;
}
return true;
}
/**
* @brief 删除/backup/snapshots/uuid对应目录
*/
void DeleteBackupProxy::deleteBackupPointDir()
{
QString uuidPath;
if (m_backupWrapper.m_iPosition == BackupPosition::LOCAL)
uuidPath = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid;
else
uuidPath = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid;
uuidPath.replace("//", "/");
QStringList args;
args << "-rf";
args << uuidPath;
QProcess::execute("rm", args);
}