From 71a970546e6721d0f774b2740d84bd7fcdec99ea Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Thu, 22 Jun 2023 19:30:10 +0400 Subject: [PATCH] [OV UTIL] Fix method in case file_size == 0 (#18187) --- .../util/include/openvino/util/file_util.hpp | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index 094a925b0b8..7e68646ceb1 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -163,6 +163,28 @@ inline int64_t file_size(const char* path) { return in.tellg(); } +/** + * @brief Returns file size for file + * @param[in] path The file name + * @return file size + */ +inline bool file_exists(const char* path) { +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) + std::wstring widefilename = ov::util::string_to_wstring(path); + const wchar_t* file_name = widefilename.c_str(); +#elif defined(__ANDROID__) || defined(ANDROID) + std::string file_name = path; + std::string::size_type pos = file_name.find('!'); + if (pos != std::string::npos) { + file_name = file_name.substr(0, pos); + } +#else + const char* file_name = path; +#endif + std::ifstream in(file_name, std::ios_base::binary | std::ios_base::ate); + return in.good(); +} + #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT /** @@ -174,6 +196,14 @@ inline int64_t file_size(const std::wstring& path) { return file_size(wstring_to_string(path).c_str()); } +/** + * @brief Returns true if file exists + * @param[in] path The file name + * @return true if file exists + */ +inline bool file_exists(const std::wstring& path) { + return file_exists(wstring_to_string(path).c_str()); +} #endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT /** @@ -187,13 +217,11 @@ inline int64_t file_size(const std::string& path) { /** * @brief Returns true if file exists - * @param[in] path The path to file + * @param[in] path The file name * @return true if file exists */ -template ::value || std::is_same::value)>::type> -inline bool file_exists(const std::basic_string& path) { - return file_size(path) > 0; +inline bool file_exists(const std::string& path) { + return file_exists(path.c_str()); } std::string get_file_ext(const std::string& path);