diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 15b2c0dabf5b53bd0d932a79e5967956d97b65f7..c1ec37711d4b877bbb0f991eb15f4a87724dae38 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -161,18 +161,18 @@ napi_value Open::Sync(napi_env env, napi_callback_info info) string uriType = uri.GetScheme(); string uriPath = uri.GetPath(); if (uriType == SCHEME_FILE) { - if (bundleName == MEDIA && uriPath.find(".") == string::npos) { - int ret = OpenFileByDatashare(pathStr, mode); + AppFileService::ModuleFileUri::FileUri fileUri(pathStr); + pathStr = fileUri.GetRealPath(); + if ((bundleName == MEDIA && pathStr.find(".") == string::npos) || + access(pathStr.c_str(), F_OK) != 0) { + int ret = OpenFileByDatashare(uri.ToString(), mode); if (ret >= 0) { - auto file = InstantiateFile(env, ret, pathStr, true).val_; + auto file = InstantiateFile(env, ret, uri.ToString(), true).val_; return file; } HILOGE("Failed to open file by Datashare"); NError(-ret).ThrowErr(env); return nullptr; - } else { - AppFileService::ModuleFileUri::FileUri fileUri(pathStr); - pathStr = fileUri.GetRealPath(); } } else if (uriType == DATASHARE) { // datashare:////#fdFromBinder=xx @@ -221,7 +221,10 @@ static NError AsyncCbExec(shared_ptr arg, string path, unsigne string uriType = uri.GetScheme(); string uriPath = uri.GetPath(); if (uriType == SCHEME_FILE) { - if (bundleName == MEDIA && uriPath.find(".") == string::npos) { + AppFileService::ModuleFileUri::FileUri fileUri(path); + pathStr = fileUri.GetRealPath(); + if ((bundleName == MEDIA && pathStr.find(".") == string::npos) || + access(pathStr.c_str(), F_OK) != 0) { int ret = OpenFileByDatashare(path, mode); if (ret >= 0) { arg->fd = ret; @@ -231,9 +234,6 @@ static NError AsyncCbExec(shared_ptr arg, string path, unsigne } HILOGE("Failed to open file by Datashare"); return NError(-ret); - } else { - AppFileService::ModuleFileUri::FileUri fileUri(path); - pathStr = fileUri.GetRealPath(); } } else if (uriType == DATASHARE) { // datashare:////#fdFromBinder=xx