[Bf-blender-cvs] [5368859a669] blender-v2.93-release: VSE: Fix disk cache potentially overwriting blend file

Richard Antalik noreply at git.blender.org
Wed May 12 20:24:49 CEST 2021


Commit: 5368859a669d8cd606a6ae6948f9c927ff8faf4d
Author: Richard Antalik
Date:   Tue May 11 12:49:49 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rB5368859a669d8cd606a6ae6948f9c927ff8faf4d

VSE: Fix disk cache potentially overwriting blend file

When disk cache path is same as blend file path, with Unix-like systems
blend file can be overwritten by disk cache directory.
This was caused by `BLI_delete(path, false, true)` when path points to
file. On Windows this would result in error message and file would not
be deleted. On Linux, file is deleted and then overwritten with cache
directory.

To further minimize chance of removing blend file, append disk cache
path with `_seq_cache` suffix.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D11217

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

M	source/blender/sequencer/intern/image_cache.c

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

diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index 089bb5a6bec..7b873d5c66e 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -352,15 +352,18 @@ static void seq_disk_cache_update_file(SeqDiskCache *disk_cache, char *path)
 }
 
 /* Path format:
- * <cache dir>/<project name>/<scene name>-<timestamp>/<seq name>/DCACHE_FNAME_FORMAT
+ * <cache dir>/<project name>_seq_cache/<scene name>-<timestamp>/<seq name>/DCACHE_FNAME_FORMAT
  */
 
 static void seq_disk_cache_get_project_dir(SeqDiskCache *disk_cache, char *path, size_t path_len)
 {
-  char main_name[FILE_MAX];
-  BLI_split_file_part(BKE_main_blendfile_path(disk_cache->bmain), main_name, sizeof(main_name));
+  char cache_dir[FILE_MAX];
+  BLI_split_file_part(BKE_main_blendfile_path(disk_cache->bmain), cache_dir, sizeof(cache_dir));
+  /* Use suffix, so that the cache directory name does not conflict with the bmain's blend file. */
+  const char *suffix = "_seq_cache";
+  strncat(cache_dir, suffix, sizeof(cache_dir) - strlen(cache_dir));
   BLI_strncpy(path, seq_disk_cache_base_dir(), path_len);
-  BLI_path_append(path, path_len, main_name);
+  BLI_path_append(path, path_len, cache_dir);
 }
 
 static void seq_disk_cache_get_dir(
@@ -421,7 +424,7 @@ static void seq_disk_cache_handle_versioning(SeqDiskCache *disk_cache)
   BLI_strncpy(path_version_file, path, sizeof(path_version_file));
   BLI_path_append(path_version_file, sizeof(path_version_file), "cache_version");
 
-  if (BLI_exists(path)) {
+  if (BLI_exists(path) && BLI_is_dir(path)) {
     FILE *file = BLI_fopen(path_version_file, "r");
 
     if (file) {



More information about the Bf-blender-cvs mailing list