[Bf-blender-cvs] [7459c0228ec] master: Cleanup: rename filename to filepath when used for full paths

Campbell Barton noreply at git.blender.org
Sat Aug 27 06:53:04 CEST 2022


Commit: 7459c0228ecd7f4cbdbd6094fa6540fc599ae674
Author: Campbell Barton
Date:   Sat Aug 27 14:51:21 2022 +1000
Branches: master
https://developer.blender.org/rB7459c0228ecd7f4cbdbd6094fa6540fc599ae674

Cleanup: rename filename to filepath when used for full paths

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

M	source/blender/blenkernel/BKE_cachefile.h
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenlib/intern/path_util.c

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

diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index fd559abf7f2..43ad340103a 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -33,7 +33,7 @@ void BKE_cachefile_eval(struct Main *bmain,
 bool BKE_cachefile_filepath_get(const struct Main *bmain,
                                 const struct Depsgraph *depsgrah,
                                 const struct CacheFile *cache_file,
-                                char r_filename[1024]);
+                                char r_filepath[1024]);
 
 double BKE_cachefile_time_offset(const struct CacheFile *cache_file, double time, double fps);
 
@@ -53,10 +53,12 @@ void BKE_cachefile_reader_free(struct CacheFile *cache_file, struct CacheReader
 bool BKE_cache_file_uses_render_procedural(const struct CacheFile *cache_file,
                                            struct Scene *scene);
 
-/* Add a layer to the cache_file. Return NULL if the filename is already that of an existing layer
- * or if the number of layers exceeds the maximum allowed layer count. */
+/**
+ * Add a layer to the cache_file. Return NULL if the `filepath` is already that of an existing
+ * layer or if the number of layers exceeds the maximum allowed layer count.
+ */
 struct CacheFileLayer *BKE_cachefile_add_layer(struct CacheFile *cache_file,
-                                               const char filename[1024]);
+                                               const char filepath[1024]);
 
 struct CacheFileLayer *BKE_cachefile_get_active_layer(struct CacheFile *cache_file);
 
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 6b6b7223a0b..fd83ac50cad 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -429,10 +429,10 @@ bool BKE_cache_file_uses_render_procedural(const CacheFile *cache_file, Scene *s
   return cache_file->use_render_procedural;
 }
 
-CacheFileLayer *BKE_cachefile_add_layer(CacheFile *cache_file, const char filename[1024])
+CacheFileLayer *BKE_cachefile_add_layer(CacheFile *cache_file, const char filepath[1024])
 {
   for (CacheFileLayer *layer = cache_file->layers.first; layer; layer = layer->next) {
-    if (STREQ(layer->filepath, filename)) {
+    if (STREQ(layer->filepath, filepath)) {
       return NULL;
     }
   }
@@ -440,7 +440,7 @@ CacheFileLayer *BKE_cachefile_add_layer(CacheFile *cache_file, const char filena
   const int num_layers = BLI_listbase_count(&cache_file->layers);
 
   CacheFileLayer *layer = MEM_callocN(sizeof(CacheFileLayer), "CacheFileLayer");
-  BLI_strncpy(layer->filepath, filename, sizeof(layer->filepath));
+  BLI_strncpy(layer->filepath, filepath, sizeof(layer->filepath));
 
   BLI_addtail(&cache_file->layers, layer);
 
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 5d8025dce8a..ce04d781980 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1304,7 +1304,7 @@ static int ptcache_frame_from_filename(const char *filename, const char *ext)
 #define MAX_PTCACHE_PATH FILE_MAX
 #define MAX_PTCACHE_FILE (FILE_MAX * 2)
 
-static int ptcache_path(PTCacheID *pid, char *filename)
+static int ptcache_path(PTCacheID *pid, char *dirname)
 {
   const char *blendfile_path = BKE_main_blendfile_path_from_global();
   Library *lib = (pid->owner_id) ? pid->owner_id->lib : NULL;
@@ -1314,13 +1314,13 @@ static int ptcache_path(PTCacheID *pid, char *filename)
   size_t i;
 
   if (pid->cache->flag & PTCACHE_EXTERNAL) {
-    strcpy(filename, pid->cache->path);
+    strcpy(dirname, pid->cache->path);
 
-    if (BLI_path_is_rel(filename)) {
-      BLI_path_abs(filename, blendfilename);
+    if (BLI_path_is_rel(dirname)) {
+      BLI_path_abs(dirname, blendfilename);
     }
 
-    return BLI_path_slash_ensure(filename); /* new strlen() */
+    return BLI_path_slash_ensure(dirname); /* new strlen() */
   }
   if ((blendfile_path[0] != '\0') || lib) {
     char file[MAX_PTCACHE_PATH]; /* we don't want the dir, only the file */
@@ -1334,28 +1334,28 @@ static int ptcache_path(PTCacheID *pid, char *filename)
     }
 
     /* Add blend file name to pointcache dir. */
-    BLI_snprintf(filename, MAX_PTCACHE_PATH, "//" PTCACHE_PATH "%s", file);
+    BLI_snprintf(dirname, MAX_PTCACHE_PATH, "//" PTCACHE_PATH "%s", file);
 
-    BLI_path_abs(filename, blendfilename);
-    return BLI_path_slash_ensure(filename); /* new strlen() */
+    BLI_path_abs(dirname, blendfilename);
+    return BLI_path_slash_ensure(dirname); /* new strlen() */
   }
 
   /* use the temp path. this is weak but better than not using point cache at all */
   /* temporary directory is assumed to exist and ALWAYS has a trailing slash */
-  BLI_snprintf(filename, MAX_PTCACHE_PATH, "%s" PTCACHE_PATH, BKE_tempdir_session());
+  BLI_snprintf(dirname, MAX_PTCACHE_PATH, "%s" PTCACHE_PATH, BKE_tempdir_session());
 
-  return BLI_path_slash_ensure(filename); /* new strlen() */
+  return BLI_path_slash_ensure(dirname); /* new strlen() */
 }
 
-static size_t ptcache_filename_ext_append(PTCacheID *pid,
-                                          char *filename,
-                                          const size_t filename_len,
+static size_t ptcache_filepath_ext_append(PTCacheID *pid,
+                                          char *filepath,
+                                          const size_t filepath_len,
                                           const bool use_frame_number,
                                           const int cfra)
 {
-  size_t len = filename_len;
+  size_t len = filepath_len;
   char *filename_ext;
-  filename_ext = filename + filename_len;
+  filename_ext = filepath + filepath_len;
   *filename_ext = '\0';
 
   /* PointCaches are inserted in object's list on demand, we need a valid index now. */
@@ -1399,14 +1399,14 @@ static size_t ptcache_filename_ext_append(PTCacheID *pid,
   return len;
 }
 
-static int ptcache_filename(
-    PTCacheID *pid, char *filename, int cfra, const bool do_path, const bool do_ext)
+static int ptcache_filepath(
+    PTCacheID *pid, char *filepath, int cfra, const bool do_path, const bool do_ext)
 {
   int len = 0;
   char *idname;
   char *newname;
-  filename[0] = '\0';
-  newname = filename;
+  filepath[0] = '\0';
+  newname = filepath;
 
   if ((pid->cache->flag & PTCACHE_EXTERNAL) == 0) {
     const char *blendfile_path = BKE_main_blendfile_path_from_global();
@@ -1417,7 +1417,7 @@ static int ptcache_filename(
 
   /* start with temp dir */
   if (do_path) {
-    len = ptcache_path(pid, filename);
+    len = ptcache_path(pid, filepath);
     newname += len;
   }
   if (pid->cache->name[0] == '\0' && (pid->cache->flag & PTCACHE_EXTERNAL) == 0) {
@@ -1437,7 +1437,7 @@ static int ptcache_filename(
   }
 
   if (do_ext) {
-    len += ptcache_filename_ext_append(pid, filename, (size_t)len, true, cfra);
+    len += ptcache_filepath_ext_append(pid, filepath, (size_t)len, true, cfra);
   }
 
   return len; /* make sure the above string is always 16 chars */
@@ -1465,7 +1465,7 @@ static PTCacheFile *ptcache_file_open(PTCacheID *pid, int mode, int cfra)
     }
   }
 
-  ptcache_filename(pid, filepath, cfra, true, true);
+  ptcache_filepath(pid, filepath, cfra, true, true);
 
   if (mode == PTCACHE_FILE_READ) {
     fp = BLI_fopen(filepath, "rb");
@@ -2596,7 +2596,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
   DIR *dir;
   struct dirent *de;
   char path[MAX_PTCACHE_PATH];
-  char filename[MAX_PTCACHE_FILE];
+  char filepath[MAX_PTCACHE_FILE];
   char path_full[MAX_PTCACHE_FILE];
   char ext[MAX_PTCACHE_PATH];
 
@@ -2631,20 +2631,20 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
           return;
         }
 
-        len = ptcache_filename(pid, filename, cfra, false, false); /* no path */
+        len = ptcache_filepath(pid, filepath, cfra, false, false); /* no path */
         /* append underscore terminator to ensure we don't match similar names
          * from objects whose names start with the same prefix
          */
-        if (len < sizeof(filename) - 2) {
-          BLI_strncpy(filename + len, "_", sizeof(filename) - 2 - len);
+        if (len < sizeof(filepath) - 2) {
+          BLI_strncpy(filepath + len, "_", sizeof(filepath) - 2 - len);
           len += 1;
         }
 
-        ptcache_filename_ext_append(pid, ext, 0, false, 0);
+        ptcache_filepath_ext_append(pid, ext, 0, false, 0);
 
         while ((de = readdir(dir)) != NULL) {
           if (strstr(de->d_name, ext)) {               /* Do we have the right extension? */
-            if (STREQLEN(filename, de->d_name, len)) { /* Do we have the right prefix. */
+            if (STREQLEN(filepath, de->d_name, len)) { /* Do we have the right prefix. */
               if (mode == PTCACHE_CLEAR_ALL) {
                 pid->cache->last_exact = MIN2(pid->cache->startframe, 0);
                 BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name);
@@ -2713,8 +2713,8 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
     case PTCACHE_CLEAR_FRAME:
       if (pid->cache->flag & PTCACHE_DISK_CACHE) {
         if (BKE_ptcache_id_exist(pid, cfra)) {
-          ptcache_filename(pid, filename, cfra, true, true); /* no path */
-          BLI_delete(filename, false, false);
+          ptcache_filepath(pid, filepath, cfra, true, true); /* no path */
+          BLI_delete(filepath, false, false);
         }
       }
       else {
@@ -2752,11 +2752,11 @@ bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
   }
 
   if (pid->cache->flag & PTCACHE_DISK_CACHE) {
-    char filename[MAX_PTCACHE_FILE];
+    char filepath[MAX_PTCACHE_FILE];
 
-    ptcache_filename(pid, filename, cfra, true, true);
+    ptcache_filepath(pid, filepath, cfra, true, true);
 
-    return BLI_exists(filename);
+    return BLI_exists(filepath);
   }
 
   PTCacheMem *pm = pid->cache->mem_cache.first;
@@ -2824,24 +2824,24 @@ void BKE_ptcache_id_time(
       DIR *dir;
       struct dirent *de;
       char path[MAX_PTCACHE_PATH];
-      char filenam

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list