[Bf-blender-cvs] [2910be8f19c] master: Cleanup: Correct semantics for .blend listing in file/asset browser

Julian Eisel noreply at git.blender.org
Mon Nov 21 12:29:40 CET 2022


Commit: 2910be8f19cf87dd57bdc3a81ce5b26fed2a8beb
Author: Julian Eisel
Date:   Mon Nov 21 12:16:30 2022 +0100
Branches: master
https://developer.blender.org/rB2910be8f19cf87dd57bdc3a81ce5b26fed2a8beb

Cleanup: Correct semantics for .blend listing in file/asset browser

When attempting to load contents of a .blend, the code would just assume
if the number of added items is 0, that means it's not a .blend (but a
directory, although the previous commit fixed that part already).
However there may be situations where a .blend file simply doesn't
contain anything of interest to be added (e.g. when listing assets
only), so have a proper "none" value for this.

===================================================================

M	source/blender/editors/space_file/filelist.cc

===================================================================

diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc
index 46211a72a82..dc59bb1286d 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -11,6 +11,7 @@
 #include <cstdlib>
 #include <cstring>
 #include <ctime>
+#include <optional>
 #include <sys/stat.h>
 
 #ifndef WIN32
@@ -3116,11 +3117,15 @@ static int filelist_readjob_list_lib_populate_from_index(FileList *filelist,
   return read_from_index + navigate_to_parent_len;
 }
 
-static int filelist_readjob_list_lib(FileList *filelist,
-                                     const char *root,
-                                     ListBase *entries,
-                                     const ListLibOptions options,
-                                     FileIndexer *indexer_runtime)
+/**
+ * \return The number of entries found if the \a root path points to a valid library file.
+ *         Otherwise returns no value (#std::nullopt).
+ */
+static std::optional<int> filelist_readjob_list_lib(FileList *filelist,
+                                                    const char *root,
+                                                    ListBase *entries,
+                                                    const ListLibOptions options,
+                                                    FileIndexer *indexer_runtime)
 {
   BLI_assert(indexer_runtime);
 
@@ -3135,7 +3140,7 @@ static int filelist_readjob_list_lib(FileList *filelist,
    * call it directly from `filelist_readjob_do` to increase readability. */
   const bool is_lib = BLO_library_path_explode(root, dir, &group, nullptr);
   if (!is_lib) {
-    return 0;
+    return std::nullopt;
   }
 
   const bool group_came_from_path = group != nullptr;
@@ -3166,7 +3171,7 @@ static int filelist_readjob_list_lib(FileList *filelist,
   BlendFileReadReport bf_reports{};
   libfiledata = BLO_blendhandle_from_file(dir, &bf_reports);
   if (libfiledata == nullptr) {
-    return 0;
+    return std::nullopt;
   }
 
   /* Add current parent when requested. */
@@ -3557,10 +3562,11 @@ static void filelist_readjob_recursive_dir_add_items(const bool do_lib,
       if (filelist->asset_library_ref) {
         list_lib_options |= LIST_LIB_ASSETS_ONLY;
       }
-      entries_num = filelist_readjob_list_lib(
+      std::optional<int> lib_entries_num = filelist_readjob_list_lib(
           filelist, subdir, &entries, list_lib_options, &indexer_runtime);
-      if (entries_num > 0) {
+      if (lib_entries_num) {
         is_lib = true;
+        entries_num += *lib_entries_num;
       }
     }



More information about the Bf-blender-cvs mailing list