140072 【文件系统】使用备份还原工具还原系统后,创建同名不同用户id的用户,插入u盘后无权限打开

This commit is contained in:
赵民勇 2022-09-13 13:56:16 +08:00
parent dc4f547e5f
commit a2ea352c18
3 changed files with 41 additions and 10 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;