diff --git a/interfaces/inner_api/file_access/include/file_access_helper.h b/interfaces/inner_api/file_access/include/file_access_helper.h index 2731c05d3cc8035a96a23bcad83477c1535d790a..806f9197a3e98ea47885d59b29a0121743a4c84c 100644 --- a/interfaces/inner_api/file_access/include/file_access_helper.h +++ b/interfaces/inner_api/file_access/include/file_access_helper.h @@ -68,6 +68,8 @@ public: const std::vector &wants); static bool IsFilePathValid(const std::string &filePath); + bool ConvertToLongLong(const std::string &str, long long& value); + bool Release(); int Access(Uri &uri, bool &isExist); int OpenFile(Uri &uri, const int flags, int &fd); @@ -90,6 +92,8 @@ public: int UnregisterNotify(Uri uri); int MoveItem(Uri &sourceFile, Uri &targetParent, std::vector &moveResult, bool force); int MoveFile(Uri &sourceFile, Uri &targetParent, std::string &fileName, Uri &newFile); + int GetQueryResult(std::string &uri, std::vector &columns, std::vector &results, + std::string &metaJson); private: sptr GetProxyByUri(Uri &uri); sptr GetProxyByBundleName(const std::string &bundleName); @@ -110,7 +114,7 @@ private: int CopyOperation(Uri &sourceUri, Uri &destUri, std::vector ©Result, bool force = false); int CopyFileOperation(Uri &sourceUri, Uri &destUri, const std::string &fileName, Uri &newFileUri); int IsDirectory(Uri &uri, bool &isDir); - + sptr token_ = nullptr; std::unordered_map> cMap_; }; diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index b8cabb35017eb4b3062ec7d615a716ae011a4a71..acb6fca861a27264b68d9a611f475d95dbafe7cc 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -41,6 +41,7 @@ namespace { constexpr int COPY_EXCEPTION = -1; constexpr int COPY_NOEXCEPTION = -2; constexpr uint32_t MAX_COPY_ERROR_COUNT = 1000; + constexpr int CONVERT_TO_TEN = 10; } sptr g_sourceExtProxy; @@ -885,10 +886,28 @@ static int GetQueryColumns(std::string &uri, std::string &metaJson, std::vector< return ERR_OK; } -static int GetQueryResult(std::string &uri, std::vector &columns, std::vector &results, +bool FileAccessHelper::ConvertToLongLong(const std::string &str, long long& value) +{ + char* end; + errno = 0; + value = std::strtoll(str.c_str(), &end, CONVERT_TO_TEN); + if (end == str.c_str()) { + return false; + } + if (errno == ERANGE) { + return false; + } + if (*end != '\0') { + return false; + } + return true; +} + +int FileAccessHelper::GetQueryResult(std::string &uri, std::vector &columns, std::vector &results, std::string &metaJson) { json jsonObject; + FileAccessHelper fileAccessHelper(nullptr, {}); for (size_t i = 0; i < columns.size(); i++) { auto memberType = FILE_RESULT_TYPE.at(columns.at(i)); // Assign a default value based on the type, When fileIo obtains an invalid value. @@ -909,7 +928,10 @@ static int GetQueryResult(std::string &uri, std::vector &columns, s if (results[i].empty()) { results[i] = "0"; } - jsonObject[columns[i]] = std::atoi(results[i].c_str()); + long long num; + if (fileAccessHelper.ConvertToLongLong(results[i], num)) { + jsonObject[columns[i]] = num; + } break; default: jsonObject[columns[i]] = " ";