From 52d78a1c1525b5dfe75aa528fdd5199eddc64b3f Mon Sep 17 00:00:00 2001 From: wangfenging Date: Mon, 9 Jun 2025 20:51:10 +0800 Subject: [PATCH] Fix: clone hap mount /storage/Users failed Signed-off-by: wangfenging --- appdata-sandbox.json | 6 +++--- modules/sandbox/sandbox_utils.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 043b888d..b6e26388 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -750,7 +750,7 @@ "sandbox-flags": [ "bind", "rec" ] }, { - "src-path": "/mnt/sandbox///mnt/storage/Users", + "src-path": "/mnt/sandbox///mnt/storage/Users", "sandbox-path": "/storage/Users", "sandbox-flags-customized": [ "MS_NODEV"], "dac-override-sensitive": "true", @@ -764,7 +764,7 @@ "check-action-status": "false" }, { - "src-path": "/mnt/sandbox///mnt/storage/userExternal", + "src-path": "/mnt/sandbox///mnt/storage/userExternal", "sandbox-path": "/storage/userExternal", "sandbox-flags-customized": [ "MS_NODEV" ], "dac-override-sensitive": "true", @@ -781,7 +781,7 @@ "sandbox-flags": [ "bind", "rec" ] }, { - "src-path": "/mnt/sandbox///mnt/storage/Users", + "src-path": "/mnt/sandbox///mnt/storage/Users", "sandbox-path": "/storage/Users", "sandbox-flags-customized": [ "MS_NODEV"], "dac-override-sensitive": "true", diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 777da7a5..edd51f02 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -84,6 +84,7 @@ namespace { const std::string g_packageName = ""; const std::string g_packageNameIndex = ""; const std::string g_variablePackageName = ""; + const std::string g_clonePackageName = ""; const std::string g_arkWebPackageName = ""; const std::string g_hostUserId = ""; const std::string g_sandBoxDir = "/mnt/sandbox/"; @@ -573,6 +574,25 @@ static std::string ReplaceHostUserId(const AppSpawningCtx *appProperty, const st return tmpSandboxPath; } +static std::string ReplaceClonePackageName(const AppSpawningCtx *appProperty, const std::string &path) +{ + std::string tmpSandboxPath = path; + AppSpawnMsgBundleInfo *bundleInfo = + reinterpret_cast(GetAppProperty(appProperty, TLV_BUNDLE_INFO)); + APPSPAWN_CHECK(bundleInfo != NULL, return "", "No bundle info in msg %{public}s", GetBundleName(appProperty)); + + std::string tmpBundlePath = bundleInfo->bundleName; + std::ostringstream variablePackageName; + if (CheckAppSpawnMsgFlag(appProperty->message, TLV_MSG_FLAGS, APP_FLAGS_CLONE_ENABLE)) { + variablePackageName << "+clone-" << bundleInfo->bundleIndex << "+" << bundleInfo->bundleName; + tmpBundlePath = variablePackageName.str(); + } + + tmpSandboxPath = replace_all(tmpSandboxPath, g_variablePackageName, tmpBundlePath); + APPSPAWN_LOGV("tmpSandboxPath %{public}s", tmpSandboxPath.c_str()); + return tmpSandboxPath; +} + string SandboxUtils::ConvertToRealPath(const AppSpawningCtx *appProperty, std::string path) { AppSpawnMsgBundleInfo *info = @@ -605,6 +625,10 @@ string SandboxUtils::ConvertToRealPath(const AppSpawningCtx *appProperty, std::s path = ReplaceVariablePackageName(appProperty, path); } + if (path.find(g_clonePackageName) != std::string::npos) { + path = ReplaceClonePackageName(appProperty, path); + } + if (path.find(g_arkWebPackageName) != std::string::npos) { path = replace_all(path, g_arkWebPackageName, getArkWebPackageName()); APPSPAWN_LOGV( -- Gitee