Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-19 16:22:40 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-19 16:53:11 +0300
commit9a1d75e0b9580819dba188afdab72295cbf47302 (patch)
treed8f4b6d299ef8531b6c205b8aa6c52454b9ce23c /source/blender/blenkernel/intern/asset_library_service.cc
parenta7075a30e2611b41af672d5987af662ce5934492 (diff)
Asset Library Service: make insensitive to trailing slashes
Make `AssetLibraryService::get_asset_library_on_disk(path)` insensitive to trailing slashes; i.e. `get_asset_library_on_disk("/path")` and `get_asset_library_on_disk("/path/¨)` will now return the same `AssetLibrary*`.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library_service.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_library_service.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/asset_library_service.cc b/source/blender/blenkernel/intern/asset_library_service.cc
index 14604def0d3..53ce2826022 100644
--- a/source/blender/blenkernel/intern/asset_library_service.cc
+++ b/source/blender/blenkernel/intern/asset_library_service.cc
@@ -24,6 +24,7 @@
#include "BKE_blender.h"
#include "BKE_callbacks.h"
+#include "BLI_path_util.h"
#include "BLI_string_ref.hh"
#include "MEM_guardedalloc.h"
@@ -54,14 +55,27 @@ void AssetLibraryService::destroy()
instance_.reset();
}
+namespace {
+std::string normalize_directory_path(StringRefNull directory)
+{
+
+ char dir_normalized[PATH_MAX];
+ STRNCPY(dir_normalized, directory.c_str());
+ BLI_path_normalize_dir(NULL, dir_normalized);
+ return std::string(dir_normalized);
+}
+} // namespace
+
AssetLibrary *AssetLibraryService::get_asset_library_on_disk(StringRefNull top_level_directory)
{
BLI_assert_msg(!top_level_directory.is_empty(),
"top level directory must be given for on-disk asset library");
- AssetLibraryPtr *lib_uptr_ptr = on_disk_libraries_.lookup_ptr(top_level_directory);
+ std::string top_dir_trailing_slash = normalize_directory_path(top_level_directory);
+
+ AssetLibraryPtr *lib_uptr_ptr = on_disk_libraries_.lookup_ptr(top_dir_trailing_slash);
if (lib_uptr_ptr != nullptr) {
- CLOG_INFO(&LOG, 2, "get \"%s\" (cached)", top_level_directory.c_str());
+ CLOG_INFO(&LOG, 2, "get \"%s\" (cached)", top_dir_trailing_slash.c_str());
return lib_uptr_ptr->get();
}
@@ -69,10 +83,10 @@ AssetLibrary *AssetLibraryService::get_asset_library_on_disk(StringRefNull top_l
AssetLibrary *lib = lib_uptr.get();
lib->on_save_handler_register();
- lib->load(top_level_directory);
+ lib->load(top_dir_trailing_slash);
- on_disk_libraries_.add_new(top_level_directory, std::move(lib_uptr));
- CLOG_INFO(&LOG, 2, "get \"%s\" (loaded)", top_level_directory.c_str());
+ on_disk_libraries_.add_new(top_dir_trailing_slash, std::move(lib_uptr));
+ CLOG_INFO(&LOG, 2, "get \"%s\" (loaded)", top_dir_trailing_slash.c_str());
return lib;
}