OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core] Migrate some file utils use fs path (#32882)
Pawel Raasz4d25dd6aa95a
diff --git a/src/bindings/c/tests/test_model_repo.cpp b/src/bindings/c/tests/test_model_repo.cppindex e94dda96d06..7db20da8a88 100644--- a/src/bindings/c/tests/test_model_repo.cpp+++ b/src/bindings/c/tests/test_model_repo.cpp@@ -41,8 +41,7 @@ std::string generate_test_xml_file() {plugin_xml_file << ov::util::FileTraits<char>::library_prefix();plugin_xml_file << "mock_engine";plugin_xml_file << OV_BUILD_POSTFIX;- plugin_xml_file << ov::util::FileTraits<char>::dot_symbol;- plugin_xml_file << ov::util::FileTraits<char>::library_ext();+ plugin_xml_file << ov::util::library_extension().string();plugin_xml_file << "\" name=\"CUSTOM\">\n";plugin_xml_file << " </plugin>\n";plugin_xml_file << " </plugins>\n";diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hppindex e6fa58dc8c0..7d5b6173339 100644--- a/src/common/util/include/openvino/util/file_util.hpp+++ b/src/common/util/include/openvino/util/file_util.hpp@@ -80,13 +80,50 @@ struct FileTraits<wchar_t> {}};+inline std::filesystem::path library_prefix() {+#if defined(_WIN32) && (defined(__MINGW32__) || defined(__MINGW64__))+ return {"lib"};+#elif defined(_WIN32)+ return {};+#else+ return {"lib"};+#endif+}+inline std::filesystem::path library_extension() {+#ifdef _WIN32+ return {".dll"};+#else+ return {".so"};+#endif+}++/**+ * @brief Creates std::filesystem::path provided by source.+ *+ * The purpose of this function is to hide platform specific issue with path creation like on Windows create from+ * literal std::string with unicode characters can lead to different path name than expected.+ *+ * @param source Source to create path. Supported types are same as for std::filesystem::path constructor.+ * @return std::filesystem::path object.+ */+template <class Source>+std::filesystem::path make_path(Source&& source) {+ if constexpr (std::is_same_v<std::add_const_t<std::remove_pointer_t<std::decay_t<Source>>>, const wchar_t>) {+ return {std::wstring(std::forward<Source>(source))};+ } else if constexpr (std::is_same_v<std::filesystem::path::string_type, std::wstring> &&+ std::is_same_v<std::decay_t<Source>, std::string>) {+ return {ov::util::string_to_wstring(std::forward<Source>(source))};+ } else {+ return {std::forward<Source>(source)};+ }+}+/*** @brief Convert path as char string to to a single-byte chain.* @param path Path as char string.* @return Reference to input path (no conversion).*/-template <class Path,- typename std::enable_if<std::is_same<typename std::decay<Path>::type, std::string>::value>::type* = nullptr>+template <class Path, typename std::enable_if_t<std::is_same_v<std::decay_t<Path>, std::string>>* = nullptr>const std::string& path_to_string(const Path& path) {return path;}@@ -97,14 +134,23 @@ const std::string& path_to_string(const Path& path) {* @param path Path as wide-char string.* @return A char string*/-template <class Path,- typename std::enable_if<std::is_same<typename std::decay<Path>::type, std::wstring>::value>::type* = nullptr>+template <class Path, typename std::enable_if_t<std::is_same_v<std::decay_t<Path>, std::wstring>>* = nullptr>std::string path_to_string(const Path& path) {return ov::util::wstring_to_string(path);}#endif+/**+ * @brief Convert std::filesystem::path single-byte chain.+ * Function resolve issue when path create from std::string which contains unicode characters.+ * @param path Path.+ * @return A char string.+ */+inline auto path_to_string(const std::filesystem::path& path) -> decltype(path_to_string(path.native())) {+ return ov::util::path_to_string(path.native());+}+/// \brief Remove path components which would allow traversing up a directory tree./// \param path A path to file/// \return A sanitized path@@ -122,14 +168,6 @@ std::string get_file_name(const std::string& path);*/std::string get_absolute_file_path(const std::string& path);-/**- * @brief Interface function to check path to file is absolute or not- * @param path - path to file, can be relative to current working directory- * @return True if path is absolute and False otherwise- * @throw runtime_error if any error occurred- */-bool is_absolute_file_path(const std::string& path);-/*** @brief Interface function to create directories recursively by given path* @param path - path to file, can be relative to current working directory@@ -172,47 +210,27 @@ inline int64_t file_size(const char* path) {#endif/**- * @brief Returns file size for file- * @param[in] path The file name- * @return file size+ * @brief Tests whether file exists at given path.+ * @param[in] path The file path.+ * @return True if file exists, false otherwise.+ * @{*/-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);- }+inline bool file_exists(const std::filesystem::path& path) noexcept {+#if defined(__ANDROID__) || defined(ANDROID)+ const auto pos = path.native().find('!');+ const auto f_status = (pos == std::string::npos) ? std::filesystem::status(path)+ : std::filesystem::status(path.native().substr(0, pos));#else- const char* file_name = path;+ const auto f_status = std::filesystem::status(path);#endif- std::ifstream in(file_name, std::ios_base::binary | std::ios_base::ate);- return in.good();+ return std::filesystem::exists(f_status) && !std::filesystem::is_directory(f_status);}-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT--/**- * @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--/**- * @brief Returns true if file exists- * @param[in] path The file name- * @return true if file exists- */-inline bool file_exists(const std::string& path) {- return file_exists(path.c_str());+template <class T>+inline bool file_exists(const std::basic_string<T>& path) noexcept {+ return file_exists(make_path(path));}+/** @} */std::string get_file_ext(const std::string& path);std::filesystem::path get_directory(const std::filesystem::path& path);@@ -236,16 +254,6 @@ using FilePath = std::filesystem::path::string_type;inline std::string from_file_path(const std::filesystem::path& path) {return path.string();}--// TODO: remove this function after all calls use Path-inline FilePath to_file_path(const std::filesystem::path& path) {-#if defined(_WIN32) && defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT)- return ov::util::string_to_wstring(path.string());-#else- return path.native();-#endif-}-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT/**@@ -277,6 +285,15 @@ inline std::basic_string<C> make_plugin_library_name(const std::basic_string<C>&FileTraits<C>::library_ext();}+inline std::filesystem::path make_plugin_library_name(const std::filesystem::path& lib_name) {+ return library_prefix().concat(lib_name.filename().native()).concat(library_extension().native());+}++inline std::filesystem::path make_plugin_library_name(const std::filesystem::path& dir_path,+ const std::filesystem::path& lib_name) {+ return dir_path / make_plugin_library_name(lib_name);+}+/*** @brief Format plugin path (canonicalize, complete to absolute or complete to file name) for further* dynamic loading by OS@@ -284,7 +301,7 @@ inline std::basic_string<C> make_plugin_library_name(const std::basic_string<C>&* shared library suffix and prefix to identify library full name* @return absolute path or file name with extension (to be found in ENV)*/-FilePath get_plugin_path(const std::string& plugin);+std::filesystem::path get_plugin_path(const std::filesystem::path& plugin);/*** @brief Find the plugins which are located together with OV library@@ -292,7 +309,7 @@ FilePath get_plugin_path(const std::string& plugin);* shared library suffix and prefix to identify library full name* @return absolute path or file name with extension (to be found in ENV)*/-FilePath get_compiled_plugin_path(const std::string& plugin);+std::filesystem::path get_compiled_plugin_path(const std::filesystem::path& plugin);/*** @brief Format plugin path (canonicalize, complete to absolute or complete to file name) for further@@ -303,7 +320,9 @@ FilePath get_compiled_plugin_path(const std::string& plugin);* @param as_abs_only - Bool value, allows return file names or not* @return absolute path or file name with extension (to be found in ENV)*/-FilePath get_plugin_path(const std::string& plugin, const std::string& xml_path, bool as_abs_only = false);+std::filesystem::path get_plugin_path(const std::filesystem::path& plugin,+ const std::filesystem::path& xml_path,+ bool as_abs_only = false);/*** @brief load binary data from file@@ -345,27 +364,5 @@ inline std::basic_string<C> make_path(const std::basic_string<C>& folder, constreturn file;return folder + ov::util::FileTraits<C>::file_separator + file;}--/**- * @brief Creates std::filesystem::path provided by source.- *- * The purpose of this function is to hide platform specific issue with path creation like on Windows create from- * literal std::string with unicode characters can lead to different path name than expected.- *- * @param source Source to create path. Supported types are same as for std::filesystem::path constructor.- * @return std::filesystem::path object.- */-template <class Source>-std::filesystem::path make_path(const Source& source) {- if constexpr (std::is_same_v<std::decay_t<Source>, wchar_t*>) {- return {std::wstring(source)};- } else if constexpr (std::is_same_v<std::filesystem::path::value_type, std::wstring::value_type> &&- std::is_same_v<Source, std::string>) {- return {ov::util::string_to_wstring(source)};- } else {- return {source};- }-}-} // namespace util} // namespace ovdiff --git a/src/common/util/src/file_util.cpp b/src/common/util/src/file_util.cppindex 806822f512d..799b4f009e9 100644--- a/src/common/util/src/file_util.cpp+++ b/src/common/util/src/file_util.cpp@@ -65,30 +65,15 @@#endifstd::string ov::util::get_file_name(const std::string& s) {- std::string rc = s;- // Linux-style separator- auto pos = s.find_last_of('/');- if (pos != std::string::npos) {- rc = s.substr(pos + 1);- return rc;- }- // Windows-style separator- pos = s.find_last_of('\\');- if (pos != std::string::npos) {- rc = s.substr(pos + 1);+ if (const auto path = make_path(s); path.has_parent_path()) {+ return path_to_string(path.filename());+ } else {+ return s;}- return rc;}-std::string ov::util::get_file_ext(const std::string& s) {- std::string rc = get_file_name(s);- auto pos = rc.find_last_of('.');- if (pos != std::string::npos) {- rc = rc.substr(pos);- } else {- rc = "";- }- return rc;+std::string ov::util::get_file_ext(const std::string& path) {+ return path_to_string(make_path(path).extension());}std::filesystem::path ov::util::get_directory(const std::filesystem::path& path) {@@ -275,19 +260,9 @@ std::string ov::util::get_absolute_file_path(const std::string& path) {throw std::runtime_error(ss.str());}-bool ov::util::is_absolute_file_path(const std::string& path) {- if (path.empty())- throw std::runtime_error("Provided path is empty");-#ifdef _WIN32- return !PathIsRelativeA(path.c_str());-#else- return path[0] == '/';-#endif // _WIN32-}-#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORTvoid ov::util::create_directory_recursive(const std::wstring& path) {- create_directory_recursive(std::filesystem::path{path});+ create_directory_recursive(make_path(path));}#endif@@ -394,93 +369,65 @@ std::wstring ov::util::get_ov_lib_path_w() {#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT-ov::util::FilePath ov::util::get_plugin_path(const std::string& plugin) {+std::filesystem::path ov::util::get_plugin_path(const std::filesystem::path& plugin) {// Assume `plugin` may contain:// 1. /path/to/libexample.so absolute path// 2. ../path/to/libexample.so path relative to working directory// 3. example library name - to be converted to 4th case// 4. libexample.so - path relative to working directory (if exists) or file to be found in ENV-- // For 1-2 cases- if (plugin.find(FileTraits<char>::file_separator) != std::string::npos)- return ov::util::to_file_path(ov::util::get_absolute_file_path(plugin));-- auto lib_name = plugin;- // For 3rd case - convert to 4th case- if (!ov::util::ends_with(plugin, ov::util::FileTraits<char>::library_ext()))- lib_name = ov::util::make_plugin_library_name({}, plugin);-- // For 4th case- auto lib_path = ov::util::to_file_path(ov::util::get_absolute_file_path(lib_name));- if (ov::util::file_exists(lib_path))- return lib_path;- return ov::util::to_file_path(lib_name);+ if (plugin.is_absolute()) {+ // 1st case+ return plugin;+ } else if (plugin.has_parent_path()) {+ // 2nd cases+ return std::filesystem::absolute(std::filesystem::weakly_canonical(plugin));+ } else {+ // 3-4 cases+ auto path = (plugin.extension() != library_extension()) ? make_plugin_library_name(plugin) : plugin;+ std::error_code ec;+ auto abs_path = std::filesystem::canonical(path, ec);+ return ec ? path : abs_path;+ }}-ov::util::FilePath ov::util::get_compiled_plugin_path(const std::string& plugin) {- const auto ov_library_path = get_ov_lib_path();+std::filesystem::path ov::util::get_compiled_plugin_path(const std::filesystem::path& plugin) {+ const auto ov_library_path = make_path(get_ov_lib_path());// plugin can be found either:+ const std::filesystem::path sub_folder_path{std::string("openvino-") + OpenVINO_VERSION};- // 1. in openvino-X.Y.Z folder relative to libopenvino.so- std::ostringstream str;- str << "openvino-" << OpenVINO_VERSION;- const auto sub_folder = str.str();-- std::string abs_file_path = ov::util::path_join({ov_library_path, sub_folder, plugin}).string();- if (ov::util::file_exists(abs_file_path))- return ov::util::to_file_path(abs_file_path);-- // 2. in the openvino.so location- abs_file_path = ov::util::path_join({ov_library_path, plugin}).string();- if (ov::util::file_exists(abs_file_path))- return ov::util::to_file_path(abs_file_path);-- auto lib_name = plugin;- // For 3rd case - convert to 4th case- if (!ov::util::ends_with(plugin, ov::util::FileTraits<char>::library_ext()))- lib_name = ov::util::make_plugin_library_name({}, plugin);-- // For 4th case- auto lib_path = ov::util::to_file_path(ov::util::get_absolute_file_path(lib_name));- if (ov::util::file_exists(lib_path))- return lib_path;- return ov::util::to_file_path(lib_name);+ if (auto plugin_path = ov_library_path / sub_folder_path / plugin; ov::util::file_exists(plugin_path)) {+ return plugin_path;+ } else if (plugin_path = ov_library_path / plugin; ov::util::file_exists(plugin_path)) {+ return plugin_path;+ } else {+ // cases 3-4+ return get_plugin_path(plugin);+ }}-ov::util::FilePath ov::util::get_plugin_path(const std::string& plugin, const std::string& xml_path, bool as_abs_only) {+std::filesystem::path ov::util::get_plugin_path(const std::filesystem::path& plugin,+ const std::filesystem::path& xml_dir,+ bool as_abs_only) {// Assume `plugin` (from XML "location" record) contains only:// 1. /path/to/libexample.so absolute path// 2. ../path/to/libexample.so path relative to XML directory// 3. example library name - to be converted to 4th case// 4. libexample.so - path relative to XML directory (if exists) or file to be found in ENV// (if `as_abs_only` is false)-- // For 1st case- if (ov::util::is_absolute_file_path(plugin))- return ov::util::to_file_path(plugin);-- auto xml_path_ = xml_path;- if (xml_path.find(ov::util::FileTraits<char>::file_separator) == std::string::npos)- xml_path_ = ov::util::path_join({".", xml_path}).string(); // treat plugins.xml as CWD/plugins.xml-- // For 2nd case- if (plugin.find(ov::util::FileTraits<char>::file_separator) != std::string::npos) {- auto path_ = ov::util::path_join({ov::util::get_directory(xml_path_), plugin}).string();- return ov::util::to_file_path(ov::util::get_absolute_file_path(path_)); // canonicalize path+ if (plugin.is_absolute()) {+ // 1st case+ return plugin;+ } else if (const auto rel_path = get_directory((xml_dir.has_parent_path() ? xml_dir : "." / xml_dir));+ plugin.has_parent_path()) {+ // 2nd case+ return std::filesystem::absolute(std::filesystem::weakly_canonical(rel_path / plugin));+ } else {+ // 3-4 cases+ auto&& lib_name = ((plugin.extension() != library_extension()) ? make_plugin_library_name(plugin) : plugin);+ auto abs_path = std::filesystem::absolute(std::filesystem::weakly_canonical(rel_path / lib_name));+ return as_abs_only || file_exists(abs_path) ? abs_path : lib_name;}-- auto lib_file_name = plugin;- // For 3rd case - convert to 4th case- if (!ov::util::ends_with(plugin, ov::util::FileTraits<char>::library_ext()))- lib_file_name = ov::util::make_plugin_library_name({}, plugin);-- // For 4th case- auto lib_path = ov::util::path_join({ov::util::get_directory(xml_path_), lib_file_name}).string();- lib_path = ov::util::get_absolute_file_path(lib_path); // canonicalize path- if (as_abs_only || ov::util::file_exists(lib_path))- return ov::util::to_file_path(lib_path);- return ov::util::to_file_path(lib_file_name);}std::vector<uint8_t> ov::util::load_binary(const std::string& path) {diff --git a/src/frontends/common/src/manager.cpp b/src/frontends/common/src/manager.cppindex 55f908a8db2..d1c0960ef19 100644--- a/src/frontends/common/src/manager.cpp+++ b/src/frontends/common/src/manager.cpp@@ -106,10 +106,10 @@ public:}void register_front_end(const std::string& name, const std::string& library_path) {- auto lib_path = ov::util::from_file_path(ov::util::get_plugin_path(library_path));+ auto lib_path = ov::util::get_plugin_path(ov::util::make_path(library_path));PluginInfo plugin;- plugin.m_file_path = lib_path;- plugin.m_file_name = ov::util::get_file_name(lib_path);+ plugin.m_file_path = ov::util::path_to_string(lib_path);+ plugin.m_file_name = ov::util::path_to_string(lib_path.filename());FRONT_END_GENERAL_CHECK(plugin.load(), "Cannot load frontend ", plugin.get_name_from_file());std::lock_guard<std::mutex> guard(m_loading_mutex);m_plugins.push_back(std::move(plugin));diff --git a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cppindex e8cba28ecc1..8e8efbfb529 100644--- a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp+++ b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp@@ -66,16 +66,10 @@ Buffer<ov::MappedMemory> TensorExternalData::load_external_mmap_data(const std::}Buffer<ov::AlignedBuffer> TensorExternalData::load_external_data(const std::string& model_dir) const {- auto full_path = model_dir == ""- ? m_data_location- : ov::util::get_absolute_file_path(ov::util::path_join({model_dir, m_data_location}).string());-#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)- ov::util::convert_path_win_style(full_path);- std::ifstream external_data_stream(ov::util::string_to_wstring(full_path).c_str(),- std::ios::binary | std::ios::in | std::ios::ate);-#else+ const auto full_path = model_dir.empty() ? ov::util::make_path(m_data_location)+ : std::filesystem::absolute(std::filesystem::weakly_canonical(+ ov::util::path_join({model_dir, m_data_location})));std::ifstream external_data_stream(full_path, std::ios::binary | std::ios::in | std::ios::ate);-#endifif (external_data_stream.fail()) {throw error::invalid_external_data{*this};diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cppindex 28e94cf73ac..2aa0759c882 100644--- a/src/inference/src/dev/core_impl.cpp+++ b/src/inference/src/dev/core_impl.cpp@@ -587,10 +587,10 @@ void ov::CoreImpl::register_compile_time_plugins() {register_plugin_in_registry_unsafe(device_name, desc);}#else- const auto& pluginPath = ov::util::get_compiled_plugin_path(plugin.second.m_plugin_path);- if (m_plugin_registry.find(device_name) == m_plugin_registry.end() && ov::util::file_exists(pluginPath)) {+ const auto& plugin_path = ov::util::get_compiled_plugin_path(ov::util::make_path(plugin.second.m_plugin_path));+ if (m_plugin_registry.find(device_name) == m_plugin_registry.end() && ov::util::file_exists(plugin_path)) {ov::AnyMap config = any_copy(plugin.second.m_default_config);- PluginDescriptor desc{pluginPath, config};+ PluginDescriptor desc{plugin_path, config};register_plugin_in_registry_unsafe(device_name, desc);}#endif@@ -620,8 +620,10 @@ void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_fiOPENVINO_THROW("Device name must not contain dot '.' symbol");}- ov::util::FilePath pluginPath =- ov::util::get_plugin_path(pugixml::get_str_attr(pluginNode, "location"), xml_config_file, by_abs_path);+ const auto& plugin_path =+ ov::util::get_plugin_path(ov::util::make_path(pugixml::get_str_attr(pluginNode, "location")),+ ov::util::make_path(xml_config_file),+ by_abs_path);// check propertiesauto propertiesNode = pluginNode.child("properties");@@ -648,7 +650,7 @@ void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_fi// fill value in plugin registry for later lazy initialization{- PluginDescriptor desc{pluginPath, config, listOfExtentions};+ PluginDescriptor desc{plugin_path, config, listOfExtentions};register_plugin_in_registry_unsafe(device_name, desc);}}@@ -710,7 +712,7 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {// Check that device plugin name is the same as requested for HW pluginsif (!plugin_name.empty() && !ov::is_virtual_device(plugin_name)) {OPENVINO_ASSERT(device_name.find(plugin_name) != std::string::npos,- desc.m_lib_location,+ ov::util::path_to_string(desc.m_lib_location)," is used for ",device_name," , while it contains implementation for ",@@ -818,7 +820,7 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {return m_plugins.emplace(device_name, plugin).first->second;} catch (const ov::Exception& ex) {OPENVINO_THROW("Failed to create plugin ",- desc.m_lib_location,+ ov::util::path_to_string(desc.m_lib_location)," for device ",device_name,"\n",@@ -1324,7 +1326,7 @@ void ov::CoreImpl::register_plugin(const std::string& plugin,OPENVINO_THROW("Device name must not contain dot '.' symbol");}- PluginDescriptor desc{ov::util::get_plugin_path(plugin), properties};+ PluginDescriptor desc{ov::util::get_plugin_path(ov::util::make_path(plugin)), properties};register_plugin_in_registry_unsafe(device_name, desc);}diff --git a/src/inference/tests/functional/ov_core_test.cpp b/src/inference/tests/functional/ov_core_test.cppindex 8a1f856de20..83e66da3a9f 100644--- a/src/inference/tests/functional/ov_core_test.cpp+++ b/src/inference/tests/functional/ov_core_test.cpp@@ -63,8 +63,7 @@ static void create_plugin_xml(const std::string& file_name, const std::string& pfile << ov::util::FileTraits<char>::library_prefix();file << "mock_engine";file << OV_BUILD_POSTFIX;- file << ov::util::FileTraits<char>::dot_symbol;- file << ov::util::FileTraits<char>::library_ext();+ file << ov::util::library_extension().string();file << "\" name=\"" << plugin_name << "\"></plugin></plugins></ie>";file.flush();file.close();diff --git a/src/inference/tests/unit/core.cpp b/src/inference/tests/unit/core.cppindex 64c4270819d..6234d3b5b97 100644--- a/src/inference/tests/unit/core.cpp+++ b/src/inference/tests/unit/core.cpp@@ -45,60 +45,59 @@ TEST(CoreTests, Throw_on_register_plugins_twice) {}TEST(CoreTests_get_plugin_path_from_xml, Use_abs_path_as_is) {- auto xml_path = "path_to_plugins.xml";- auto lib_path = ov::util::get_absolute_file_path("test_name.ext"); // CWD/test_name.ext- for (auto as_abs_only : std::vector<bool>{true, false}) {- auto abs_path = from_file_path(get_plugin_path(lib_path, xml_path, as_abs_only));- EXPECT_TRUE(is_absolute_file_path(abs_path));- EXPECT_STREQ(abs_path.c_str(), lib_path.c_str());+ auto xml_path = std::filesystem::path("path_to_plugins.xml");+ auto lib_path = std::filesystem::absolute("test_name.ext"); // CWD/test_name.ext+ for (auto&& as_abs_only : {true, false}) {+ const auto abs_path = get_plugin_path(lib_path, xml_path, as_abs_only);+ EXPECT_TRUE(abs_path.is_absolute());+ EXPECT_EQ(abs_path, lib_path);}}TEST(CoreTests_get_plugin_path_from_xml, Convert_relative_path_as_relative_to_xmldir) {- auto xml_path = "path_to_plugins.xml";- auto lib_path = ov::util::make_path(std::string("."), std::string("test_name.ext")); // ./test_name.ext- for (auto as_abs_only : std::vector<bool>{true, false}) {- auto abs_path = from_file_path(get_plugin_path(lib_path, xml_path, as_abs_only)); // XMLDIR/test_name.ext- EXPECT_TRUE(is_absolute_file_path(abs_path));-- auto ref_path = ov::util::get_absolute_file_path(lib_path);- EXPECT_STREQ(abs_path.c_str(), ref_path.c_str()); // XMLDIR/test_name.ext == CWD/test_name.ext+ auto xml_path = std::filesystem::path("path_to_plugins.xml");+ auto lib_path = std::filesystem::path(".") / "test_name.ext"; // ./test_name.ext+ for (auto&& as_abs_only : {true, false}) {+ const auto abs_path = get_plugin_path(lib_path, xml_path, as_abs_only);+ EXPECT_TRUE(abs_path.is_absolute());++ const auto ref_path = std::filesystem::absolute(std::filesystem::weakly_canonical(lib_path));+ EXPECT_EQ(abs_path, ref_path); // XMLDIR/test_name.ext == CWD/test_name.ext}}TEST(CoreTests_get_plugin_path_from_xml, Convert_filename_to_abs_path_if_as_abs_only) {- auto xml_path = "path_to_plugins.xml";- auto name = "test_name.ext"; // test_name.ext- auto abs_path = from_file_path(get_plugin_path(name, xml_path, true)); // XMLDIR/libtest_name.ext.so- EXPECT_TRUE(is_absolute_file_path(abs_path));-- auto lib_name = ov::util::make_plugin_library_name({}, std::string(name));- auto ref_path = ov::util::get_absolute_file_path(lib_name);- EXPECT_STREQ(abs_path.c_str(), ref_path.c_str()); // XMLDIR/libtest_name.ext.so == CWD/libtest_name.ext.so+ auto xml_path = std::filesystem::path("path_to_plugins.xml");+ auto name = std::filesystem::path("test_name.ext"); // test_name.ext+ auto abs_path = get_plugin_path(name, xml_path, true); // XMLDIR/libtest_name.ext.so+ EXPECT_TRUE(abs_path.is_absolute());++ auto lib_name = ov::util::make_plugin_library_name(name);+ auto ref_path = std::filesystem::absolute(std::filesystem::weakly_canonical(lib_name));+ EXPECT_EQ(abs_path, ref_path); // XMLDIR/libtest_name.ext.so == CWD/libtest_name.ext.so}TEST(CoreTests_get_plugin_path_from_xml, Use_filename_if_not_as_abs_only) {- auto xml_path = "path_to_plugins.xml";- auto name = "test_name.ext"; // test_name.ext- auto lib_name = from_file_path(get_plugin_path(name, xml_path)); // libtest_name.ext.so- auto ref_name = ov::util::make_plugin_library_name({}, std::string(name));- EXPECT_STREQ(lib_name.c_str(), ref_name.c_str());+ auto xml_path = std::filesystem::path("path_to_plugins.xml");+ auto name = std::filesystem::path("test_name.ext"); // test_name.ext+ auto lib_name = get_plugin_path(name, xml_path); // libtest_name.ext.so+ auto ref_name = ov::util::make_plugin_library_name(name);+ EXPECT_EQ(lib_name, ref_name);}TEST(CoreTests_get_plugin_path, Use_abs_path_as_is) {- auto lib_name = ov::util::make_plugin_library_name({}, std::string("test_name")); // libtest_name.so- auto lib_path = ov::util::get_absolute_file_path(lib_name);- auto abs_path = from_file_path(get_plugin_path(lib_path));- EXPECT_TRUE(is_absolute_file_path(abs_path));- EXPECT_STREQ(abs_path.c_str(), lib_path.c_str());+ auto lib_name = ov::util::make_plugin_library_name("test_name"); // libtest_name.so+ auto lib_path = std::filesystem::absolute(std::filesystem::weakly_canonical("." / lib_name));+ auto abs_path = get_plugin_path(lib_path);+ EXPECT_TRUE(abs_path.is_absolute());+ EXPECT_EQ(abs_path, lib_path);}TEST(CoreTests_get_plugin_path, Relative_path_is_from_workdir) {- auto lib_name =- ov::util::make_plugin_library_name(std::string("."), std::string("test_name")); // ./libtest_name.so- auto abs_path = from_file_path(get_plugin_path(lib_name));- EXPECT_TRUE(is_absolute_file_path(abs_path));- EXPECT_STREQ(abs_path.c_str(), get_absolute_file_path(lib_name).c_str());+ auto lib_name = ov::util::make_plugin_library_name(".", "test_name"); // ./libtest_name.so+ auto abs_path = get_plugin_path(lib_name);+ EXPECT_TRUE(abs_path.is_absolute());+ EXPECT_EQ(abs_path, std::filesystem::absolute(std::filesystem::weakly_canonical(lib_name)));}class CoreTests_get_plugin_path_Class : public ::testing::Test {@@ -111,26 +110,29 @@ public:}void TearDown() override {- std::remove(lib_path.c_str());+ if (ov::util::file_exists(lib_path)) {+ std::ignore = std::filesystem::remove(lib_path);+ }}- std::string lib_name = ov::util::make_plugin_library_name({}, std::string("test_name")); // libtest_name.so- std::string lib_path = ov::util::get_absolute_file_path(lib_name); // CWD/libtest_name.so+ std::filesystem::path lib_name = ov::util::make_plugin_library_name("test_name"); // libtest_name.so+ std::filesystem::path lib_path =+ std::filesystem::absolute(std::filesystem::weakly_canonical(lib_name)); // /CWD/libtest_name.so};TEST_F(CoreTests_get_plugin_path_Class, Filename_is_from_workdir_if_exists) {- auto abs_path = from_file_path(get_plugin_path(lib_name)); // libtest_name.so -> CWD/libtest_name.so- EXPECT_TRUE(is_absolute_file_path(abs_path));- EXPECT_STREQ(abs_path.c_str(), get_absolute_file_path(lib_name).c_str());+ auto abs_path = get_plugin_path(lib_name); // libtest_name.so -> CWD/libtest_name.so+ EXPECT_TRUE(abs_path.is_absolute());+ EXPECT_EQ(abs_path, std::filesystem::absolute(std::filesystem::weakly_canonical(lib_name)));}TEST(CoreTests_get_plugin_path, Use_filename_as_is_if_not_exist_in_workdir) {auto lib_name = "test_name.ext";- auto abs_path = from_file_path(get_plugin_path(lib_name)); // libtest_name.ext.so -> libtest_name.ext.so- EXPECT_FALSE(is_absolute_file_path(abs_path));+ auto abs_path = get_plugin_path(lib_name); // libtest_name.ext.so -> libtest_name.ext.so+ EXPECT_FALSE(abs_path.is_absolute());- auto ref_path = ov::util::make_plugin_library_name({}, std::string(lib_name));- EXPECT_STREQ(abs_path.c_str(), ref_path.c_str());+ auto ref_path = ov::util::make_plugin_library_name(lib_name);+ EXPECT_EQ(abs_path, ref_path);}TEST(CoreTests_check_device_name, is_config_applicable) {diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cppindex 2abdf2df4ec..d97745a31e9 100644--- a/src/plugins/auto/src/plugin.cpp+++ b/src/plugins/auto/src/plugin.cpp@@ -326,7 +326,7 @@ ov::Any Plugin::get_property(const std::string& name, const ov::AnyMap& argument: get_core()->get_available_devices();std::vector<std::string> capabilities;- for (auto const& device : device_list) {+ for (const auto& device : device_list) {try {auto dev_capabilities = get_core()->get_property(device, ov::device::capabilities);capabilities.insert(capabilities.end(), dev_capabilities.begin(), dev_capabilities.end());@@ -770,13 +770,13 @@ std::string Plugin::get_device_list(ov::AnyMap& properties,dev_properties);elseblobId = ov::ModelCache::compute_hash(model_path, dev_properties);- std::string cached_model_path = ov::util::make_path(cache_dir, blobId + ".blob");+ const auto cached_model_path = ov::util::make_path(cache_dir) / (blobId + ".blob");bool is_blob_file_exist = ov::util::file_exists(cached_model_path);num_blob_files += is_blob_file_exist;LOG_DEBUG_TAG("device: %s %s cached blob: %s ",device.c_str(),is_blob_file_exist ? "found" : "not found",- cached_model_path.c_str());+ ov::util::path_to_string(cached_model_path).c_str());}if (enable_startup_cpu && num_blob_files) {diff --git a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cppindex c8f420e24f5..b5beed49808 100644--- a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp+++ b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/caching_tests.cpp@@ -359,12 +359,8 @@ TEST_P(CompileModelLoadFromFileTestBase, CanLoadFromFileWithoutException) {#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORTTEST_P(CompileModelLoadFromFileTestBase, CanCreateCacheDirAndDumpBinariesUnicodePath) {- std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();- auto hash = std::hash<std::string>()(test_name);- std::stringstream ss;- ss << std::this_thread::get_id();std::string cache_path = ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator +- "compiledModel_" + std::to_string(hash) + "_" + ss.str() + "_" + GetTimestamp() + "_cache";+ "compiledModel_" + utils::generateTestFilePrefix() + "_cache";std::wstring postfix = L"_" + ov::test::utils::test_unicode_postfix_vector[0];std::wstring cache_path_w = ov::util::string_to_wstring(cache_path) + postfix;auto cache_path_mb = ov::util::wstring_to_string(cache_path_w);@@ -405,10 +401,7 @@ TEST_P(CompileModelLoadFromFileTestBase, CanCreateCacheDirAndDumpBinariesUnicode} catch (std::exception& ex) {// Cleanup in case of any exceptionif (ov::util::directory_exists(cache_path_w)) {- // Check that folder contains cache files and remove them- ASSERT_GT(- ov::test::utils::removeFilesWithExt<opt::FORCE>(cache_path_w, ov::util::string_to_wstring("blob")),- 0);+ ov::test::utils::removeFilesWithExt<opt::FORCE>(cache_path_w, ov::util::string_to_wstring("blob"));ov::test::utils::removeFile(model_xml_path_w);ov::test::utils::removeFile(model_bin_path_w);ov::test::utils::removeDir(cache_path_w);