[Bf-blender-cvs] [1c883fe6468] master: Cleanup: make BLI_make_exist local to the file selector

Campbell Barton noreply at git.blender.org
Sat Feb 15 00:41:14 CET 2020


Commit: 1c883fe6468c9fd3859d24e63590d4011984d52e
Author: Campbell Barton
Date:   Sat Feb 15 10:33:16 2020 +1100
Branches: master
https://developer.blender.org/rB1c883fe6468c9fd3859d24e63590d4011984d52e

Cleanup: make BLI_make_exist local to the file selector

This isn't a general utility, and the name wasn't descriptive.

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

M	source/blender/blenlib/BLI_path_util.h
M	source/blender/blenlib/intern/path_util.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/filelist.c

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

diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 75d5cb286ac..ec911c11a8c 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -34,7 +34,6 @@ void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
 const char *BLI_getenv(const char *env) ATTR_NONNULL(1);
 
 void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
-void BLI_make_exist(char *dir);
 bool BLI_make_existing_file(const char *name);
 void BLI_split_dirfile(
     const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
@@ -92,8 +91,10 @@ void BLI_cleanup_path(const char *relabase, char *path) ATTR_NONNULL(2);
 bool BLI_filename_make_safe(char *fname) ATTR_NONNULL(1);
 bool BLI_path_make_safe(char *path) ATTR_NONNULL(1);
 
-/* go back one directory */
+/* Go back one directory. */
 bool BLI_parent_dir(char *path) ATTR_NONNULL();
+/* Go back until the directory is found. */
+bool BLI_parent_dir_until_exists(char *path) ATTR_NONNULL();
 
 bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL();
 bool BLI_path_frame(char *path, int frame, int digits) ATTR_NONNULL();
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index dff1f77c1ab..f8e703dbb56 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -728,6 +728,21 @@ bool BLI_parent_dir(char *path)
   }
 }
 
+/**
+ * Strips off nonexistent (or non-accessible) subdirectories from the end of *dir,
+ * leaving the path of the lowest-level directory that does exist and we can read.
+ */
+bool BLI_parent_dir_until_exists(char *dir)
+{
+  bool valid_path = true;
+
+  /* Loop as long as cur path is not a dir, and we can get a parent path. */
+  while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir))) {
+    /* pass */
+  }
+  return (valid_path && dir[0]);
+}
+
 /**
  * Looks for a sequence of "#" characters in the last slash-separated component of *path,
  * returning the indexes of the first and one past the last character in the sequence in
@@ -1312,29 +1327,6 @@ const char *BLI_getenv(const char *env)
 #endif
 }
 
-/**
- * Strips off nonexistent (or non-accessible) subdirectories from the end of *dir,
- * leaving the path of the lowest-level directory that does exist and we can read.
- */
-void BLI_make_exist(char *dir)
-{
-  bool valid_path = true;
-
-  /* Loop as long as cur path is not a dir, and we can get a parent path. */
-  while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir))) {
-    /* pass */
-  }
-
-  /* If we could not find an existing dir, use default root... */
-  if (!valid_path || !dir[0]) {
-#ifdef WIN32
-    get_default_root(dir);
-#else
-    strcpy(dir, "/");
-#endif
-  }
-}
-
 /**
  * Ensures that the parent directory of *name exists.
  *
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index b0ff67844d8..5ed936bc749 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -137,5 +137,6 @@ void file_execute_region_panels_register(struct ARegionType *art);
 
 /* file_utils.c */
 void file_tile_boundbox(const ARegion *ar, FileLayout *layout, const int file, rcti *r_bounds);
+void file_path_existing_or_default_root(char *dir);
 
 #endif /* __FILE_INTERN_H__ */
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 800726c6fb0..b328b32263c 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1046,12 +1046,23 @@ int filelist_geticon(struct FileList *filelist, const int index, const bool is_m
 
 /* ********** Main ********** */
 
+static void parent_dir_until_exists_or_default_root(char *dir)
+{
+  if (!BLI_parent_dir_until_exists(dir)) {
+#ifdef WIN32
+    get_default_root(dir);
+#else
+    strcpy(dir, "/");
+#endif
+  }
+}
+
 static bool filelist_checkdir_dir(struct FileList *UNUSED(filelist),
                                   char *r_dir,
                                   const bool do_change)
 {
   if (do_change) {
-    BLI_make_exist(r_dir);
+    parent_dir_until_exists_or_default_root(r_dir);
     return true;
   }
   else {
@@ -1072,7 +1083,7 @@ static bool filelist_checkdir_lib(struct FileList *UNUSED(filelist),
 
   if (do_change && !is_valid) {
     /* if not a valid library, we need it to be a valid directory! */
-    BLI_make_exist(r_dir);
+    parent_dir_until_exists_or_default_root(r_dir);
     return true;
   }
   return is_valid;



More information about the Bf-blender-cvs mailing list