yhkylin-backup-tools/backup-daemon/myprocess/mountbackupprocess.cpp

51 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef MOUNTBACKUPPROCESS_CPP
#define MOUNTBACKUPPROCESS_CPP
#include <QFile>
#include <QtDebug>
#include "mountbackupprocess.h"
#include "../../common/mydefine.h"
#include "../../common/utils.h"
MountBackupProcess::MountBackupProcess(QObject* parent)
: QObject(parent)
, m_p(new QProcess(this))
{
connect(m_p, &QProcess::readyReadStandardError, this, [&]() {
QByteArray err = m_p->readAllStandardError();
qCritical("%s", err.data());
});
}
bool MountBackupProcess::Do(const QString& diskUuid)
{
QString rootPath(Utils::getSysRootPath());
// 若备份路径下的xml已经存在则说明已经挂载过了
QString backupXmlPath = rootPath + BACKUP_XML_PATH;
backupXmlPath.replace("//", "/");
QFile file(backupXmlPath);
if (file.exists())
return true;
QStringList arguments;
QString backupPartion = rootPath + BACKUP_PATH;
backupPartion.replace("//","/");
arguments << QString("-o") << QString("rw") << QString("/dev/disk/by-uuid/%1").arg(diskUuid) << backupPartion;
m_p->start("mount", arguments);
if (!m_p->waitForStarted()) {
qFatal("mount rw /backup process start failed!");
return false;
}
if (!m_p->waitForFinished()) {
qFatal("mount rw backup process end failed!");
return false;
}
return true;
}
#endif // MOUNTBACKUPPROCESS_CPP