[OV UTIL] Fix method in case file_size == 0 (#18187)

This commit is contained in:
Irina Efode
2023-06-22 19:30:10 +04:00
committed by GitHub
parent 92ec5991b2
commit 71a970546e

View File

@@ -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 <typename C,
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
inline bool file_exists(const std::basic_string<C>& 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);