From b8c18f29def9d973086840cbcbdc7ff8b910a605 Mon Sep 17 00:00:00 2001 From: zhangkaixiang Date: Fri, 21 Apr 2023 16:00:22 +0800 Subject: [PATCH] fixed 5aa67b3 from https://gitee.com/panqiangbiao/filemanagement_file_api/pulls/256 remove the uri name Signed-off-by: zhangkaixiang --- .../kits/js/src/mod_fs/properties/open.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 5102cbdf7..10dc568e6 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -57,6 +57,25 @@ static tuple GetJsFlags(napi_env env, const NFuncArg &funcAr return { true, mode }; } +static string DealWithUriWithName(string str) +{ + static uint32_t MEET_COUNT = 6; + uint32_t count = 0; + uint32_t index; + for (index = 0; index < str.length(); index++) { + if (str[index] == '/') { + count++; + } + if (count == MEET_COUNT) { + break; + } + } + if (count == MEET_COUNT) { + str = str.substr(0, index); + } + return str; +} + static NVal InstantiateFile(napi_env env, int fd, string pathOrUri, bool isUri) { napi_value objFile = NClass::InstantiateClass(env, FileNExporter::className_, {}); @@ -107,6 +126,9 @@ static int OpenFileByDatashare(string path, unsigned int flags) HILOGE("Failed to connect to datashare"); return -E_PERMISSION; } + HILOGI("Before Media Path is %{public}s", path.c_str()); + path = DealWithUriWithName(path); + HILOGI("After Media Path is %{public}s", path.c_str()); Uri uri(path); fd = dataShareHelper->OpenFile(uri, CommonFunc::GetModeFromFlags(flags)); return fd; -- Gitee