From a2ea352c187fd20b30fec54059f9eb53cb1dfb15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=B0=91=E5=8B=87?= Date: Tue, 13 Sep 2022 13:56:16 +0800 Subject: [PATCH] =?UTF-8?q?140072=20=E3=80=90=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E3=80=91=E4=BD=BF=E7=94=A8=E5=A4=87=E4=BB=BD=E8=BF=98?= =?UTF-8?q?=E5=8E=9F=E5=B7=A5=E5=85=B7=E8=BF=98=E5=8E=9F=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=88=9B=E5=BB=BA=E5=90=8C=E5=90=8D=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=94=A8=E6=88=B7id=E7=9A=84=E7=94=A8=E6=88=B7?= =?UTF-8?q?=EF=BC=8C=E6=8F=92=E5=85=A5u=E7=9B=98=E5=90=8E=E6=97=A0?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/systemrestoreproxy.cpp | 41 +++++++++++++++++++++++----- backup-daemon/systemrestoreproxy.h | 6 +++- common/utils.cpp | 4 +-- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/backup-daemon/systemrestoreproxy.cpp b/backup-daemon/systemrestoreproxy.cpp index a16809e..850e541 100755 --- a/backup-daemon/systemrestoreproxy.cpp +++ b/backup-daemon/systemrestoreproxy.cpp @@ -16,6 +16,7 @@ SystemRestoreProxy::SystemRestoreProxy() { m_bSuccess = false; m_p = nullptr; + m_bRetainUserData = false; } /** @@ -335,6 +336,7 @@ void SystemRestoreProxy::restoreSystem() // 自动更新的备份还原时保留用户数据 if (m_curUuid == AUTO_BACKUP_UUID || m_backupWrapper.m_type == BackupType::RESTORE_SYSTEM_WITH_DATA) { args = getRsyncArgs(SystemRestoreScene::RESTORE_SYSTEM_WITH_DATA); + m_bRetainUserData = true; } else { args = getRsyncArgs(SystemRestoreScene::SYSTEM_RESTORE); } @@ -358,11 +360,11 @@ void SystemRestoreProxy::restoreSystem() fileIfSync.replace("//", "/"); QFileInfo file(fileIfSync); QDateTime beginTime = file.fileTime(QFileDevice::FileModificationTime); -// if (Utils::isHuawei990() && FACTORY_BACKUP_UUID == m_curUuid && m_backupWrapper.m_type == BackupType::RESTORE_SYSTEM) { -// // 出厂还原有的机器上删除/home/xxx有残留,故在此再强制删除一下,sudo rm -rf命令一遍还删除不了(报错:无法删除/home/xx/.config:目录非空,应该是删除后又自动生成了),多删除几次还不是非常干净,^_^ -// removeHome(Utils::getSysRootPath() + "/home"); -// removeHome(Utils::getSysRootPath() + "/data/home"); -// } + if (FACTORY_BACKUP_UUID == m_curUuid && m_backupWrapper.m_type == BackupType::RESTORE_SYSTEM) { + // 出厂还原有的机器上删除/home/xxx有残留,故在此再强制删除一下,sudo rm -rf命令一遍还删除不了(报错:无法删除/home/xx/.config:目录非空,应该是删除后又自动生成了),多删除几次还不是非常干净,^_^ + removeHome(Utils::getSysRootPath() + "/home"); + removeHome(Utils::getSysRootPath() + "/data/home"); + } QProcess::execute("sync"); Utils::wait(20); Utils::updateSyncFile(); @@ -384,6 +386,29 @@ void SystemRestoreProxy::restoreSystem() m_p->start(args, false); } +/** + * @brief 获取备份点里存在家目录的用户列表 + * @param void + * @return 获取备份点里存在家目录的用户列表 + */ +QStringList SystemRestoreProxy::getBackupPointUsers() +{ + // 根据备份点里的/home或/data/home的子目录进行统计 + QStringList users = getBackupPointUsers(m_backupPath + "/home"); + users.append(getBackupPointUsers(m_backupPath + "/data/home")); + return users; +} + +QStringList SystemRestoreProxy::getBackupPointUsers(const QString& path) +{ + QDir dir(path); + if (dir.exists()) { + return dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs); + } else { + return QStringList(); + } +} + /** * @brief 删除home子目录,此处主要用于删除用户残留信息 * @param path @@ -393,13 +418,15 @@ void SystemRestoreProxy::removeHome(const QString& path) { QDir dir(path); if (dir.exists()) { + QStringList retainUsers = getBackupPointUsers(m_backupPath + path); + bool needRm = false; QString subcmd("rm -rf "); QString delDirs; QStringList list = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs); for (const QString& item : list) { - // 出厂备份里面的/home/oem保留 - if (item == "oem") + // 出厂备份里面的/home/oem等保留 + if (retainUsers.contains(item)) continue ; QString subPath = path; diff --git a/backup-daemon/systemrestoreproxy.h b/backup-daemon/systemrestoreproxy.h index 68a3b33..00a5313 100755 --- a/backup-daemon/systemrestoreproxy.h +++ b/backup-daemon/systemrestoreproxy.h @@ -42,6 +42,9 @@ private: void restoreSystem(); // 删除home下的用户家目录 void removeHome(const QString& path); + // 获取备份点里存在家目录的用户列表 + QStringList getBackupPointUsers(); + QStringList getBackupPointUsers(const QString& path); /** * @brief 根据场景获取rsync命令参数 @@ -67,7 +70,8 @@ private: RsyncPathToDirProcess *m_p; // 当前备份节点 ParseBackupList::BackupPoint m_backupPoint; - + // 是否保留用户数据 + bool m_bRetainUserData; }; #endif // SYSTEMRESTOREPROXY_H diff --git a/common/utils.cpp b/common/utils.cpp index cabca0a..2bce0c9 100755 --- a/common/utils.cpp +++ b/common/utils.cpp @@ -478,7 +478,7 @@ bool Utils::generateExcludePathsFile() // 系统安装后有的会将/data/home /data/root挂载到的/home /root上,实际文件是存放在/data/home /data/root下面,为了统一标准保留/home /root排除/data/home /data/root QStringList excludes; Utils::excludeFstabBindPath(excludes); - Utils::excludeSomeHomePath(excludes); + // Utils::excludeSomeHomePath(excludes); Utils::excludeCustomizePath(excludes); for (const QString& item : excludes) { in << item << END_LINE; @@ -535,7 +535,7 @@ QStringList Utils::getFromExcludePathsFile() // 系统安装后有的会将/data/home /data/root挂载到的/home /root上,实际文件是存放在/data/home /data/root下面 QStringList excludes; Utils::excludeFstabBindPath(excludes); - Utils::excludeSomeHomePath(excludes); + // Utils::excludeSomeHomePath(excludes); Utils::excludeCustomizePath(excludes); for (const QString& item : excludes) { list << item;