diff --git a/interfaces/innerkits/native/file_uri/include/file_uri.h b/interfaces/innerkits/native/file_uri/include/file_uri.h index 1f8f50410c7bbeebf2718b2df408b00983d10b69..a0737021726e40bbfc66d3c7395a06956b7829bd 100644 --- a/interfaces/innerkits/native/file_uri/include/file_uri.h +++ b/interfaces/innerkits/native/file_uri/include/file_uri.h @@ -36,7 +36,7 @@ public: explicit FileUri(const std::string &uriOrPath); ~FileUri() = default; - Uri uri_; + sptr uri_ = sptr(new Uri("")); }; } // ModuleFileUri } // namespace AppFileService diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index f2af06226bd36679c74b318409e3cd9e0b36ca15..adfa66a59102450b1de859e12413a6697193e521 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -59,7 +59,7 @@ static bool CheckFileManagerFullMountEnable() string FileUri::GetName() { - string sandboxPath = SandboxHelper::Decode(uri_.GetPath()); + string sandboxPath = SandboxHelper::Decode(uri_->GetPath()); size_t posLast = sandboxPath.find_last_of("/"); if (posLast == string::npos) { return ""; @@ -97,8 +97,8 @@ static string DecodeBySA(const string &uri) string FileUri::GetPath() { - string sandboxPath = SandboxHelper::Decode(uri_.GetPath()); - string bundleName = uri_.GetAuthority(); + string sandboxPath = SandboxHelper::Decode(uri_->GetPath()); + string bundleName = uri_->GetAuthority(); if (bundleName == MEDIA_AUTHORITY && sandboxPath.find(".") != string::npos) { size_t pos = sandboxPath.rfind("/"); if (pos == string::npos) { @@ -112,11 +112,11 @@ string FileUri::GetPath() string FileUri::GetRealPath() { - string sandboxPath = SandboxHelper::Decode(uri_.GetPath()); + string sandboxPath = SandboxHelper::Decode(uri_->GetPath()); string realPath = sandboxPath; - string bundleName = uri_.GetAuthority(); + string bundleName = uri_->GetAuthority(); if (bundleName == FILE_MANAGER_AUTHORITY && - uri_.ToString().find(NETWORK_PARA) == string::npos && + uri_->ToString().find(NETWORK_PARA) == string::npos && (access(realPath.c_str(), F_OK) == 0 || CheckFileManagerFullMountEnable())) { return realPath; } @@ -131,7 +131,7 @@ string FileUri::GetRealPath() } } if (((!bundleName.empty()) && (bundleName != BUNDLE_NAME)) || - uri_.ToString().find(NETWORK_PARA) != string::npos) { + uri_->ToString().find(NETWORK_PARA) != string::npos) { realPath = PATH_SHARE + MODE_RW + bundleName + sandboxPath; if (access(realPath.c_str(), F_OK) != 0) { realPath = PATH_SHARE + MODE_R + bundleName + sandboxPath; @@ -142,14 +142,14 @@ string FileUri::GetRealPath() string FileUri::GetRealPathBySA(const std::string &targetBundleName) { - string sandboxPath = DecodeBySA(uri_.GetPath()); + string sandboxPath = DecodeBySA(uri_->GetPath()); if (sandboxPath.empty()) { return ""; } string realPath = sandboxPath; - string bundleName = uri_.GetAuthority(); + string bundleName = uri_->GetAuthority(); if (bundleName == FILE_MANAGER_AUTHORITY && - uri_.ToString().find(NETWORK_PARA) == string::npos && + uri_->ToString().find(NETWORK_PARA) == string::npos && (access(realPath.c_str(), F_OK) == 0 || CheckFileManagerFullMountEnable())) { return realPath; } @@ -159,12 +159,12 @@ string FileUri::GetRealPathBySA(const std::string &targetBundleName) string FileUri::ToString() { - return uri_.ToString(); + return uri_->ToString(); } string FileUri::GetFullDirectoryUri() { - string uri = uri_.ToString(); + string uri = uri_->ToString(); struct stat fileInfo; if (stat(GetRealPath().c_str(), &fileInfo) != 0) { LOGE("fileInfo is error,%{public}s", strerror(errno)); @@ -185,9 +185,9 @@ string FileUri::GetFullDirectoryUri() bool FileUri::IsRemoteUri() { - size_t pos = uri_.ToString().find(NETWORK_PARA); - if (pos != string::npos && pos > 0 && pos < uri_.ToString().size() - NETWORK_PARA.size()) { - if (uri_.ToString().substr(pos + NETWORK_PARA.size()).find(BACKFLASH) == string::npos) { + size_t pos = uri_->ToString().find(NETWORK_PARA); + if (pos != string::npos && pos > 0 && pos < uri_->ToString().size() - NETWORK_PARA.size()) { + if (uri_->ToString().substr(pos + NETWORK_PARA.size()).find(BACKFLASH) == string::npos) { return true; } } @@ -203,10 +203,11 @@ bool FileUri::CheckUriFormat(const std::string &uri) return true; } -FileUri::FileUri(const string &uriOrPath): uri_( - (uriOrPath.find(FILE_SCHEME_PREFIX) == 0) ? uriOrPath : CommonFunc::GetUriFromPath(uriOrPath) -) -{} +FileUri::FileUri(const string &uriOrPath) +{ + string uri = (uriOrPath.find(FILE_SCHEME_PREFIX) == 0) ? uriOrPath : CommonFunc::GetUriFromPath(uriOrPath); + uri_ = sptr(new Uri(uri)); +} } } // namespace AppFileService } // namespace OHOS \ No newline at end of file