2021-08-06 10:20:03 +08:00
|
|
|
|
#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()) {
|
2021-12-11 09:49:09 +08:00
|
|
|
|
qCritical("mount rw /backup process start failed!");
|
2021-08-06 10:20:03 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_p->waitForFinished()) {
|
2021-12-11 09:49:09 +08:00
|
|
|
|
qCritical("mount rw backup process end failed!");
|
2021-08-06 10:20:03 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 09:24:05 +08:00
|
|
|
|
bool MountBackupProcess::umountBackupPartition()
|
|
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << QString("/backup");
|
|
|
|
|
m_p->start("umount", arguments);
|
|
|
|
|
if (!m_p->waitForStarted()) {
|
2021-12-26 18:15:21 +08:00
|
|
|
|
qCritical("umount /backup process start failed!");
|
2021-10-26 09:24:05 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_p->waitForFinished()) {
|
2021-12-26 18:15:21 +08:00
|
|
|
|
qCritical("umount /backup process end failed!");
|
2021-12-11 09:49:09 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 卸载目录挂载
|
|
|
|
|
* @param mountPath,挂载的目录
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
bool MountBackupProcess::umount(const QString& mountPath)
|
|
|
|
|
{
|
2022-01-25 16:36:17 +08:00
|
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << mountPath;
|
|
|
|
|
m_p->start("umount", arguments);
|
|
|
|
|
if (!m_p->waitForStarted()) {
|
|
|
|
|
qCritical() << tr("umount %1 process start failed!").arg(mountPath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-12-11 09:49:09 +08:00
|
|
|
|
|
2022-01-25 16:36:17 +08:00
|
|
|
|
if (!m_p->waitForFinished()) {
|
|
|
|
|
qCritical() << tr("umount %1 process end failed!").arg(mountPath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-12-11 09:49:09 +08:00
|
|
|
|
|
2022-01-25 16:36:17 +08:00
|
|
|
|
return true;
|
2021-12-11 09:49:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 挂载
|
|
|
|
|
* @param source 源
|
|
|
|
|
* @param target 目标目录
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
bool MountBackupProcess::mount(const QString& source, const QString& target, const QString& options)
|
|
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
if (!options.isEmpty())
|
|
|
|
|
arguments << options;
|
|
|
|
|
arguments << source;
|
|
|
|
|
arguments << target;
|
|
|
|
|
|
|
|
|
|
m_p->start("mount", arguments);
|
|
|
|
|
if (!m_p->waitForStarted()) {
|
|
|
|
|
qCritical("mount process start failed!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_p->waitForFinished()) {
|
|
|
|
|
qCritical("mount process end failed!");
|
2021-10-26 09:24:05 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 10:20:03 +08:00
|
|
|
|
#endif // MOUNTBACKUPPROCESS_CPP
|