diff options
author | Richard Antalik <richardantalik@gmail.com> | 2021-05-11 13:49:49 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2021-05-12 21:18:45 +0300 |
commit | 5368859a669d8cd606a6ae6948f9c927ff8faf4d (patch) | |
tree | d721cda2cefc2e01966aefaa1a9d6a48c628465b /source/blender/sequencer | |
parent | 7bccdfd8d2b4d1efa11ccf32b7e6281eb09d4f2b (diff) |
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
Diffstat (limited to 'source/blender/sequencer')
-rw-r--r-- | source/blender/sequencer/intern/image_cache.c | 13 |
1 files changed, 8 insertions, 5 deletions
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) { |