[Bf-blender-cvs] [7475012e24a] master: Cleanup: rename BLI_paths_equal to BLI_path_cmp_normalized

Campbell Barton noreply at git.blender.org
Fri Jan 28 04:53:36 CET 2022


Commit: 7475012e24ad02c116ad2dcdcd7b36ca60f62103
Author: Campbell Barton
Date:   Fri Jan 28 13:59:06 2022 +1100
Branches: master
https://developer.blender.org/rB7475012e24ad02c116ad2dcdcd7b36ca60f62103

Cleanup: rename BLI_paths_equal to BLI_path_cmp_normalized

Changes to recent addition: c85c52f2ce478ab0e30c5e93fd5a5cb812db232f.

Having both BLI_paths_equal and BLI_path_cmp made it ambiguous
which should be used, as `BLI_paths_equal` wasn't the equivalent to
`BLI_path_cmp(..) == 0` as it is for string equals macro `STREQ(..)`.
It's also a more specialized function which is not used for path
comparison throughout Blender's internal path handling logic.

Instead rename this `BLI_path_cmp_normalized` and return the result of
`BLI_path_cmp` to make it clear paths are modified before comparison.

Also add comments about the conventions for Blender's path comparison
as well as a possible equivalent to Python's `os.path.samefile`
for checking if two paths point to the same location on the file-system.

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

M	source/blender/blenlib/BLI_path_util.h
M	source/blender/blenlib/intern/path_util.c
M	source/blender/io/usd/intern/usd_writer_material.cc

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

diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index a2bb8ca47c5..3c40a311f6f 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -380,11 +380,6 @@ void BLI_path_normalize_unc_16(wchar_t *path_16);
 void BLI_path_normalize_unc(char *path_16, int maxlen);
 #endif
 
-/**
- * Returns true if the given paths are equal.
- */
-bool BLI_paths_equal(const char *p1, const char *p2);
-
 /**
  * Appends a suffix to the string, fitting it before the extension
  *
@@ -409,6 +404,19 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
 #  define BLI_path_ncmp strncmp
 #endif
 
+/**
+ * Returns the result of #BLI_path_cmp with both paths normalized and slashes made native.
+ *
+ * \note #BLI_path_cmp is used for Blender's internal logic to consider paths to be the same
+ * #BLI_path_cmp_normalized may be used in when handling other kinds of paths
+ * (e.g. importers/exporters) but should be used consistently.
+ *
+ * Checking the normalized paths is not a guarantee the paths reference different files.
+ * An equivalent to Python's `os.path.samefile` could be supported for checking if paths
+ * point to the same location on the file-system (following symbolic-links).
+ */
+int BLI_path_cmp_normalized(const char *p1, const char *p2);
+
 /* These values need to be hard-coded in structs, dna does not recognize defines */
 /* also defined in `DNA_space_types.h`. */
 #ifndef FILE_MAXDIR
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 250415c11f9..65e8c151e8d 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1830,7 +1830,7 @@ void BLI_path_slash_native(char *path)
 #endif
 }
 
-bool BLI_paths_equal(const char *p1, const char *p2)
+int BLI_path_cmp_normalized(const char *p1, const char *p2)
 {
   /* Normalize the paths so we can compare them. */
   char norm_p1[FILE_MAX];
@@ -1845,5 +1845,5 @@ bool BLI_paths_equal(const char *p1, const char *p2)
   BLI_path_normalize(NULL, norm_p1);
   BLI_path_normalize(NULL, norm_p2);
 
-  return BLI_path_cmp(norm_p1, norm_p2) == 0;
+  return BLI_path_cmp(norm_p1, norm_p2);
 }
diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc
index 34fd884f51a..af448dc7794 100644
--- a/source/blender/io/usd/intern/usd_writer_material.cc
+++ b/source/blender/io/usd/intern/usd_writer_material.cc
@@ -397,7 +397,7 @@ static void export_in_memory_texture(Image *ima,
     return;
   }
 
-  if (BLI_paths_equal(export_path, image_abs_path) && BLI_exists(image_abs_path)) {
+  if ((BLI_path_cmp_normalized(export_path, image_abs_path) == 0) && BLI_exists(image_abs_path)) {
     /* As a precaution, don't overwrite the original path. */
     return;
   }
@@ -668,7 +668,7 @@ static void copy_tiled_textures(Image *ima,
       continue;
     }
 
-    if (BLI_paths_equal(src_tile_path, dest_tile_path)) {
+    if (BLI_path_cmp_normalized(src_tile_path, dest_tile_path) == 0) {
       /* Source and destination paths are the same, don't copy. */
       continue;
     }
@@ -703,7 +703,7 @@ static void copy_single_file(Image *ima, const std::string &dest_dir, const bool
     return;
   }
 
-  if (BLI_paths_equal(source_path, dest_path)) {
+  if (BLI_path_cmp_normalized(source_path, dest_path) == 0) {
     /* Source and destination paths are the same, don't copy. */
     return;
   }



More information about the Bf-blender-cvs mailing list