问题修改

This commit is contained in:
zhaominyong 2021-11-20 17:50:17 +08:00
parent 46bb97df33
commit 0ce234a999
5 changed files with 56 additions and 0 deletions

View File

@ -424,6 +424,7 @@ bool SystemBackupProxy::backupSystem()
connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) {
if (result) {
m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING;
m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath));
QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH;
xmlPath.replace("//", "/");
ParseBackupList parse(xmlPath);
@ -432,6 +433,7 @@ bool SystemBackupProxy::backupSystem()
Utils::writeBackupLog(m_backupPoint.m_time + ","
+ m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size);
Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName);
m_bSuccess = true;
}
emit this->workResult(result);

View File

@ -432,6 +432,7 @@ bool UDiskSystemBackupProxy::backup(const QStringList &args)
connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) {
if (result) {
m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING;
m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath));
QString xmlPath = m_backupWrapper.m_prefixDestPath + BACKUP_XML_PATH;
xmlPath.replace("//", "/");
ParseBackupList parse(xmlPath);
@ -440,6 +441,8 @@ bool UDiskSystemBackupProxy::backup(const QStringList &args)
Utils::writeBackupLog(m_backupPoint.m_time + ","
+ m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size);
Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName);
m_bSuccess = true;
}
emit this->workResult(result);

View File

@ -17,6 +17,7 @@
#define BACKUP_IMGBACKUP_PATH "/backup/imgbackup"
#define IMGBACKUP_PATH "/imgbackup"
#define UDISK_MKSQUASHFS_IMG_NAME "dst.img"
#define UDISK_UNIQUE_SETTINGS "/backup/udisk_unique_file"
#define DATA_PATH "/data"

View File

@ -17,6 +17,8 @@
#include <functional>
#include <QRegularExpression>
#include <QProcess>
#include <QSettings>
#include <QTextCodec>
#include "mylittleparse.h"
#include "mydefine.h"
@ -1005,3 +1007,37 @@ QHash<QString, QString> Utils::getLeftSizeOfPartitions()
}
return hash;
}
/**
* @brief
* @param path
* @return
*/
qint64 Utils::getDirOrFileSize(const QString &path)
{
char cmd[1024] = { 0 };
sprintf(cmd, "du -sb '%s' 2>/dev/null | awk '{print $1}'", path.toLocal8Bit().data()); //s:total k:1024 bytes b:1 byte
QString qsSize;
Utils::executeCMD(cmd, qsSize);
qsSize.replace("\n", "");
qsSize = qsSize.trimmed();
return qsSize.toLongLong();
}
/**
* @brief uuid及其名称
* @param uuid
* @param backupName
*/
void Utils::update_backup_unique_settings(const QString &uuid, const QString &backupName)
{
// 由于历史原因原来只校验U盘备份的唯一性,文件名暂不改变
QString backupUniqueSetting = Utils::getSysRootPath() + UDISK_UNIQUE_SETTINGS;
backupUniqueSetting.replace("//", "/");
QSettings udisk_unique_settings(backupUniqueSetting, QSettings::IniFormat);
udisk_unique_settings.setIniCodec(QTextCodec::codecForName("utf-8"));
udisk_unique_settings.beginGroup(backupName);
udisk_unique_settings.setValue("uuid", uuid);
udisk_unique_settings.endGroup();
}

View File

@ -254,6 +254,20 @@ public:
*/
static QHash<QString, QString> getLeftSizeOfPartitions();
/**
* @brief
* @param path
* @return
*/
static qint64 getDirOrFileSize(const QString &path);
/**
* @brief uuid及其名称
* @param uuid
* @param backupName
*/
static void update_backup_unique_settings(const QString &uuid, const QString &backupName);
private:
// 系统根目录,默认"/"
static QString m_sysRootPath;