mirror of https://github.com/linuxdeepin/linglong
fix: fix removable storage bind mount
Refactored the logic for binding removable storage mounts to improve readability and reduce unnecessary complexity. Previously, the code used a `do...while(false)` loop that wasn't actually serving a purpose. The code now directly processes each propagation path (/media, /mnt) without the unnecessary loop construct. This simplifies the control flow and makes the code easier to understand and maintain. Also changed how symlinks are handled in removable storage mounts, adding the target directory to the mounts vector, so that applications inside the container can access the target directory, instead of breaking the symlink. Influence: 1. Verify removable storage mounts function correctly after the changes. 2. Ensure applications inside the container can access removable storage devices without errors. 3. Specifically test applications that rely on symbolic links within / media or /mnt. fix: 修复可移动存储绑定挂载 简化了绑定可移动存储挂载点的逻辑,以提高可读性并减少不必要的复杂性。 之 前,代码使用了一个 `do...while(false)` 循环,但实际上并没有起到任何作 用。 现在,代码直接处理每个传播路径(/media、/mnt),而无需不必要的循环 结构。 这简化了控制流程,使代码更易于理解和维护。 此外,更改了可移动存储 挂载中符号链接的处理方式,将目标目录添加到挂载向量,以便容器内的应用程序 可以访问目标目录,而不是破坏符号链接。 Influence: 1. 验证更改后可移动存储挂载功能是否正常。 2. 确保容器内的应用程序可以访问可移动存储设备而不会出错。 3. 专门测试依赖于 /media 或 /mnt 中符号链接的应用程序。
This commit is contained in:
parent
6f7ca1c69d
commit
0246d9d9b6
|
|
@ -279,43 +279,39 @@ ContainerCfgBuilder &ContainerCfgBuilder::bindRemovableStorageMounts() noexcept
|
|||
std::vector<std::string> propagationPaths{ "/media", "/mnt" };
|
||||
|
||||
for (const auto &path : propagationPaths) {
|
||||
do {
|
||||
auto mountDir = std::filesystem::path(path);
|
||||
auto status = std::filesystem::symlink_status(mountDir, ec);
|
||||
auto mountPath = std::filesystem::path(path);
|
||||
auto status = std::filesystem::symlink_status(mountPath, ec);
|
||||
if (ec) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (status.type() == std::filesystem::file_type::symlink) {
|
||||
auto targetDir = std::filesystem::read_symlink(mountPath, ec);
|
||||
if (ec) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (status.type() == std::filesystem::file_type::symlink) {
|
||||
auto targetDir = std::filesystem::read_symlink(mountDir, ec);
|
||||
if (ec) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto destinationDir = "/" + targetDir.string();
|
||||
if (!std::filesystem::exists(destinationDir, ec)) {
|
||||
break;
|
||||
}
|
||||
|
||||
removableStorageMounts = {
|
||||
Mount{ .destination = destinationDir,
|
||||
.options = string_list{ "rbind" },
|
||||
.source = destinationDir,
|
||||
.type = "bind" },
|
||||
Mount{ .destination = path,
|
||||
.options = string_list{ "rbind", "ro", "copy-symlink" },
|
||||
.source = path,
|
||||
.type = "bind" },
|
||||
};
|
||||
} else {
|
||||
removableStorageMounts = {
|
||||
Mount{ .destination = path,
|
||||
.options = string_list{ "rbind" },
|
||||
.source = path,
|
||||
.type = "bind" },
|
||||
};
|
||||
auto destinationDir = "/" + targetDir.string();
|
||||
if (!std::filesystem::exists(destinationDir, ec)) {
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
removableStorageMounts->emplace_back(Mount{ .destination = destinationDir,
|
||||
.options = string_list{ "rbind" },
|
||||
.source = destinationDir,
|
||||
.type = "bind" });
|
||||
|
||||
removableStorageMounts->emplace_back(
|
||||
Mount{ .destination = path,
|
||||
.options = string_list{ "rbind", "ro", "copy-symlink" },
|
||||
.source = path,
|
||||
.type = "bind" });
|
||||
} else {
|
||||
removableStorageMounts->emplace_back(Mount{ .destination = path,
|
||||
.options = string_list{ "rbind" },
|
||||
.source = path,
|
||||
.type = "bind" });
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
|
@ -356,7 +352,7 @@ ContainerCfgBuilder &ContainerCfgBuilder::forwardDefaultEnv() noexcept
|
|||
"GDMSESSION",
|
||||
"QT_WAYLAND_FORCE_DPI",
|
||||
"GIO_LAUNCHED_DESKTOP_FILE", // 系统监视器
|
||||
"GNOME_DESKTOP_SESSION_ID", // gnome 桌面标识,有些应用会读取此变量以使用gsettings配置,
|
||||
"GNOME_DESKTOP_SESSION_ID", // gnome 桌面标识,有些应用会读取此变量以使用gsettings配置,
|
||||
// 如chrome
|
||||
"TERM",
|
||||
// 控制应用将渲染任务路由到 NVIDIA 独立显卡
|
||||
|
|
|
|||
Loading…
Reference in New Issue