-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CORE] OV file utils file_size use std file path #28462
base: master
Are you sure you want to change the base?
Changes from all commits
887dd2b
04671c7
b334528
c0ec93e
dce5d59
701cd96
97f2a96
c0345b1
66615dc
a1e8053
f34b2d2
2d071bf
3b2fbae
eed127e
067224b
22d6712
2e7cf52
e9c2cca
71e2206
c8bdb3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,7 +10,9 @@ | |||||||||||||||
#include <string> | ||||||||||||||||
#include <vector> | ||||||||||||||||
|
||||||||||||||||
#include "openvino/util/file_path.hpp" | ||||||||||||||||
#include "openvino/util/util.hpp" | ||||||||||||||||
#include "openvino/util/wstring_convert_util.hpp" | ||||||||||||||||
|
||||||||||||||||
namespace ov { | ||||||||||||||||
namespace util { | ||||||||||||||||
|
@@ -89,19 +91,6 @@ const std::string& path_to_string(const Path& path) { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT | ||||||||||||||||
/** | ||||||||||||||||
* @brief Conversion from wide character string to a single-byte chain. | ||||||||||||||||
* @param wstr A wide-char string | ||||||||||||||||
* @return A multi-byte string | ||||||||||||||||
*/ | ||||||||||||||||
std::string wstring_to_string(const std::wstring& wstr); | ||||||||||||||||
/** | ||||||||||||||||
* @brief Conversion from single-byte chain to wide character string. | ||||||||||||||||
* @param str A null-terminated string | ||||||||||||||||
* @return A wide-char string | ||||||||||||||||
*/ | ||||||||||||||||
std::wstring string_to_wstring(const std::string& str); | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* @brief Convert path as wide character string to a single-byte chain. | ||||||||||||||||
* @param path Path as wide-char string. | ||||||||||||||||
|
@@ -172,11 +161,23 @@ bool directory_exists(const std::string& path); | |||||||||||||||
bool directory_exists(const std::wstring& path); | ||||||||||||||||
#endif | ||||||||||||||||
|
||||||||||||||||
inline ov::util::Path cut_android_path(const ov::util::Path& file_name) { | ||||||||||||||||
const auto& file_name_result = file_name.native(); | ||||||||||||||||
const auto pos = file_name_result.find('!'); | ||||||||||||||||
if (pos != std::decay_t<decltype(file_name_result)>::npos) { | ||||||||||||||||
return ov::util::Path(file_name_result.substr(0, pos)); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return file_name; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* @brief Returns file size for file | ||||||||||||||||
* @param[in] path The file name | ||||||||||||||||
* @return file size | ||||||||||||||||
*/ | ||||||||||||||||
[[deprecated( | ||||||||||||||||
"This function is deprecated use file_size(const ov::util::Path& path) instead. Will be removed in 2026.0")]] | ||||||||||||||||
inline int64_t file_size(const char* path) { | ||||||||||||||||
barnasm1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) | ||||||||||||||||
std::wstring widefilename = ov::util::string_to_wstring(path); | ||||||||||||||||
|
@@ -194,6 +195,17 @@ inline int64_t file_size(const char* path) { | |||||||||||||||
return in.tellg(); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
inline int64_t file_size(const ov::util::Path& path) { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This function should probably be wrapper to |
||||||||||||||||
#if defined(__ANDROID__) || defined(ANDROID) | ||||||||||||||||
const ov::util::Path& cut_path = cut_android_path(path); | ||||||||||||||||
std::ifstream in(cut_path, std::ios_base::binary | std::ios_base::ate); | ||||||||||||||||
return in.tellg(); | ||||||||||||||||
#else | ||||||||||||||||
std::ifstream in(path, std::ios_base::binary | std::ios_base::ate); | ||||||||||||||||
return in.tellg(); | ||||||||||||||||
#endif | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* @brief Returns file size for file | ||||||||||||||||
* @param[in] path The file name | ||||||||||||||||
|
@@ -223,8 +235,11 @@ inline bool file_exists(const char* path) { | |||||||||||||||
* @param[in] path The file name | ||||||||||||||||
* @return file size | ||||||||||||||||
*/ | ||||||||||||||||
inline int64_t file_size(const wchar_t* path) { | ||||||||||||||||
return file_size(wstring_to_string(path)); | ||||||||||||||||
} | ||||||||||||||||
inline int64_t file_size(const std::wstring& path) { | ||||||||||||||||
return file_size(wstring_to_string(path).c_str()); | ||||||||||||||||
return file_size(wstring_to_string(path)); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
|
@@ -237,15 +252,6 @@ inline bool file_exists(const std::wstring& path) { | |||||||||||||||
} | ||||||||||||||||
#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* @brief Returns file size for file | ||||||||||||||||
* @param[in] path The file name | ||||||||||||||||
* @return file size | ||||||||||||||||
*/ | ||||||||||||||||
inline int64_t file_size(const std::string& path) { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is removed? Consider add deprecation note to other function which are not using Path type. |
||||||||||||||||
return file_size(path.c_str()); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* @brief Returns true if file exists | ||||||||||||||||
* @param[in] path The file name | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "openvino/util/util.hpp" | ||
|
||
namespace ov { | ||
namespace util { | ||
|
||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT | ||
/** | ||
* @brief Conversion from wide character string to a single-byte chain. | ||
* @param wstr A wide-char string | ||
* @return A multi-byte string | ||
*/ | ||
std::string wstring_to_string(const std::wstring& wstr); | ||
/** | ||
* @brief Conversion from single-byte chain to wide character string. | ||
* @param str A null-terminated string | ||
* @return A wide-char string | ||
*/ | ||
std::wstring string_to_wstring(const std::string& str); | ||
|
||
#endif | ||
|
||
} // namespace util | ||
} // namespace ov |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/util/wstring_convert_util.hpp" | ||
|
||
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT | ||
|
||
# include <codecvt> | ||
# include <locale> | ||
|
||
# ifdef _WIN32 | ||
# include <windows.h> | ||
# endif | ||
|
||
# ifdef __clang__ | ||
# pragma clang diagnostic push | ||
# pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
# endif | ||
|
||
std::string ov::util::wstring_to_string(const std::wstring& wstr) { | ||
# ifdef _WIN32 | ||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); | ||
std::string strTo(size_needed, 0); | ||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); | ||
return strTo; | ||
# else | ||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_decoder; | ||
return wstring_decoder.to_bytes(wstr); | ||
# endif | ||
} | ||
|
||
std::wstring ov::util::string_to_wstring(const std::string& string) { | ||
const char* str = string.c_str(); | ||
# ifdef _WIN32 | ||
int strSize = static_cast<int>(std::strlen(str)); | ||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0); | ||
std::wstring wstrTo(size_needed, 0); | ||
MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed); | ||
return wstrTo; | ||
# else | ||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_encoder; | ||
std::wstring result = wstring_encoder.from_bytes(str); | ||
return result; | ||
# endif | ||
} | ||
|
||
# ifdef __clang__ | ||
# pragma clang diagnostic pop | ||
# endif | ||
|
||
#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not required can be still internal part of
file_size