From a3e68c8452bab9697ac090f027efd0f22c814921 Mon Sep 17 00:00:00 2001 From: zhangkaixiang Date: Fri, 21 Apr 2023 16:00:22 +0800 Subject: [PATCH] fixed 445ba6b from https://gitee.com/zkx48/filemanagement_file_api/pulls/256 remove the uri name Signed-off-by: zhangkaixiang --- .../kits/js/src/mod_fs/properties/open.cpp | 20 +++++++++++++++++++ 1 file changed, 20 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..08dacd66e 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,7 @@ static int OpenFileByDatashare(string path, unsigned int flags) HILOGE("Failed to connect to datashare"); return -E_PERMISSION; } + path = DealWithUriWithName(path); Uri uri(path); fd = dataShareHelper->OpenFile(uri, CommonFunc::GetModeFromFlags(flags)); return fd; -- Gitee