diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index dc04f46b13e880c2d7ea8c4602ef11a5edb09fcf..f9367528036ae13520ce8b16158379ba6f340fae 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -129,12 +129,8 @@ ohos_shared_library("fs") { ] external_deps = [ - "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", - "ability_runtime:napi_base_context", - "ability_runtime:static_subscriber_extension", "c_utils:utils", "data_share:datashare_common", "data_share:datashare_consumer", diff --git a/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp b/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp index 35e3804b30bd08b485f9931cff28117b476d98a3..34955cac21411ee8ddaca33c014f4c5182f02cfa 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/open_v9.cpp @@ -28,7 +28,6 @@ #include "../../common/uni_error.h" #include "../common_func.h" #include "datashare_helper.h" -#include "napi_base_context.h" #include "remote_uri.h" #include "ability.h" @@ -81,16 +80,12 @@ static int OpenFileByDatashare(napi_env env, napi_value argv, string path) int fd = -1; sptr remote = new IRemoteStub(); if (remote == nullptr) { - UniError(errno).ThrowErr(env); - return fd; + return ENOMEM; } dataShareHelper = DataShare::DataShareHelper::Creator(remote->AsObject(), MEDIALIBRARY_DATA_URI); Uri uri(path); fd = dataShareHelper->OpenFile(uri, MEDIA_FILEMODE_READONLY); - if (fd == -1) { - UniError(errno).ThrowErr(env); - } return fd; } @@ -116,7 +111,7 @@ napi_value OpenV9::Sync(napi_env env, napi_callback_info info) auto File = InstantiateFile(env, fd, path.get()).val_; return File; } - UniError(errno).ThrowErr(env); + UniError(-1).ThrowErr(env); return nullptr; } uv_loop_s *loop = nullptr; @@ -166,7 +161,7 @@ napi_value OpenV9::Async(napi_env env, napi_callback_info info) arg->uri = ""; return UniError(ERRNO_NOERR); } - return UniError(errno); + return UniError(-1); } uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env, &loop); diff --git a/interfaces/kits/native/BUILD.gn b/interfaces/kits/native/BUILD.gn index b700811c7cfa55a02193c7390d128ae2e9eddd00..1f585e054e4129c12ef76527db5b1d61bb4998b6 100644 --- a/interfaces/kits/native/BUILD.gn +++ b/interfaces/kits/native/BUILD.gn @@ -29,6 +29,7 @@ ohos_shared_library("remote_uri_native") { public_configs = [ ":remote_uri_config" ] external_deps = [ + "ability_base:zuri", "access_token:libaccesstoken_sdk", "c_utils:utils", "ipc:ipc_core", diff --git a/interfaces/kits/native/remote_uri/remote_uri.cpp b/interfaces/kits/native/remote_uri/remote_uri.cpp index 6e88a13b589bbcda90e0f69e3501f4c180827bd2..2fe67fab149c32fdb1982ba421ef67e78a7fe770 100644 --- a/interfaces/kits/native/remote_uri/remote_uri.cpp +++ b/interfaces/kits/native/remote_uri/remote_uri.cpp @@ -28,55 +28,17 @@ namespace ModuleRemoteUri { using namespace std; -bool RemoteUri::IsMediaUri(const string &path) +bool RemoteUri::IsMediaUri(const string &uriString) { - string::size_type posDataShare = path.find(SCHEME_TAG); - if (posDataShare == string::npos) { - return false; - } - string scheme = path.substr(0, posDataShare); - if (scheme != SCHEME) { - return false; - } - - string::size_type pathSlashPos = path.find(PATH_SYMBOL); - if (pathSlashPos == string::npos) { - return false; - } - - string pathNoScheme = path.substr(pathSlashPos); - if (pathNoScheme.empty() || pathNoScheme.length() <= MEDIA.length()) { - return false; - } - - char s1 = pathNoScheme[0]; - char s2 = pathNoScheme[1]; - if (s1 != PATH_SYMBOL[0] || s2 != PATH_SYMBOL[0]) { - return false; - } - - string str = pathNoScheme.substr(2); - if (str.find(PATH_SYMBOL) == string::npos) { - return false; - } - - int position = str.find_first_of(PATH_SYMBOL); - int len = position + 1; - if (str.length() == len) { - return false; - } - - string s = str.substr(len); - if (s.empty() || s.length() < MEDIA.length()) { - return false; - } - - string media = str.substr(len, MEDIA.length()); - if (media != MEDIA) { - return false; + RemoteUri remoteUri = RemoteUri(uriString); + string scheme = remoteUri.GetScheme(); + string path = remoteUri.GetPath(); + std::size_t len = MEDIA.length(); + if (path.length() > len) { + string media = path.substr(0, len); + return scheme == SCHEME && media == MEDIA; } - - return true; + return false; } static bool IsAllDigits(string fdStr) diff --git a/interfaces/kits/native/remote_uri/remote_uri.h b/interfaces/kits/native/remote_uri/remote_uri.h index be6a535ea0f55f1a12b194aabdf28f16282d1ffd..b8250fa77b0d3ac16e0038db10cb8b50fb4d0ff4 100644 --- a/interfaces/kits/native/remote_uri/remote_uri.h +++ b/interfaces/kits/native/remote_uri/remote_uri.h @@ -19,6 +19,7 @@ #include #include #include +#include "uri.h" namespace OHOS { namespace DistributedFS { @@ -32,18 +33,18 @@ const string REMOTE_URI_TAG = "fdFromBinder"; const string SCHEME_TAG = ":"; const string SCHEME = "datashare"; const string ZERO_FD = "0"; -const string MEDIA = "media"; +const string MEDIA = "/media/"; const string PATH_SYMBOL = "/"; const int MAX_URI_SIZE = 128; -class RemoteUri { +class RemoteUri : public OHOS::Uri { static setfdFromBinder; static void RemoveFd(int fd); public: - RemoteUri() {} + explicit RemoteUri(const std::string& uriString): Uri(uriString) {} static bool IsRemoteUri(const string& path, int &fd, const int& flags = O_RDONLY); static int ConvertUri(const int &fd, string &remoteUri); static int OpenRemoteUri(const string &remoteUri); - static bool IsMediaUri(const string &path); + static bool IsMediaUri(const string &uriString); ~RemoteUri() {} }; std::setRemoteUri::fdFromBinder;