From ef2a955d855f25119f7e8e34309c901e32cb8974 Mon Sep 17 00:00:00 2001 From: zhangkaixiang Date: Sun, 14 May 2023 00:22:17 +0800 Subject: [PATCH] handle fuse dir special Signed-off-by: zhangkaixiang --- .../native/file_share/include/file_share.h | 6 +++-- .../native/file_share/src/file_share.cpp | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/native/file_share/include/file_share.h b/interfaces/innerkits/native/file_share/include/file_share.h index 61973fe0b..37f76141a 100644 --- a/interfaces/innerkits/native/file_share/include/file_share.h +++ b/interfaces/innerkits/native/file_share/include/file_share.h @@ -33,13 +33,15 @@ enum SHARE_FILE_TYPE { DIR_TYPE = 0, FILE_TYPE }; namespace { const string FILE_SCHEME = "file"; -const string DATA_STORAGE_PATH = "/data/storage/"; +const string CMD_GET_PID = "pidof "; +const string PID_FLAG = ""; const string PACKAGE_NAME_FLAG = ""; const string CURRENT_USER_ID_FLAG = ""; const string DATA_APP_EL2_PATH = "/data/service/el2/"; const string SHARE_R_PATH = "/r/"; const string SHARE_RW_PATH = "/rw/"; const string SHARE_PATH = "/share/"; +const string DLP_MANAGER_BUNDLE_NAME = "com.ohos.dlpmanager"; const vector SANDBOX_PATH = { "/data/storage/el1/bundle", @@ -62,7 +64,7 @@ const vector LOWER_PATH = { "/data/local/ark-cache/", "/data/local/ark-profile//", "/mnt/hmdfs//account/merge_view/data/", - "/mnt/sandbox//data/fuse" + "/proc//root/data/fuse" }; } diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 71159d61a..be352eafd 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -79,6 +79,20 @@ static bool IsExistFile(const string &path) return S_ISREG(buf.st_mode); } +static string GetPidFromProcessName(const string &processName) +{ + FILE *fp; + const int32_t bufLen = 100; + char buf[bufLen] = {'\0'}; + string cmd = CMD_GET_PID + processName; + if((fp = popen(cmd.c_str(), "r")) != NULL) { + if(fgets(buf, bufLen, fp) != NULL) { + return string(buf); + } + } + return ""; +} + static int32_t GetLowerPath(string &lowerPathHead, const string &lowerPathTail, FileShareInfo &info) { if (lowerPathHead.empty()) { @@ -95,6 +109,18 @@ static int32_t GetLowerPath(string &lowerPathHead, const string &lowerPathTail, PACKAGE_NAME_FLAG.length(), info.providerBundleName_); } + if (info.providerBundleName_ == DLP_MANAGER_BUNDLE_NAME) { + string pid = GetPidFromProcessName(DLP_MANAGER_BUNDLE_NAME); + if (pid.empty()) { + LOGE("Failed to get id from process name"); + return -EINVAL; + } + if (lowerPathHead.find(PID_FLAG) != string::npos) { + lowerPathHead = lowerPathHead.replace(lowerPathHead.find(PID_FLAG), + PID_FLAG.length(), pid); + } + } + info.providerLowerPath_ = lowerPathHead + lowerPathTail; return 0; } -- Gitee