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
This commit is contained in:
@@ -352,15 +352,18 @@ static void seq_disk_cache_update_file(SeqDiskCache *disk_cache, char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Path format:
|
/* 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)
|
static void seq_disk_cache_get_project_dir(SeqDiskCache *disk_cache, char *path, size_t path_len)
|
||||||
{
|
{
|
||||||
char main_name[FILE_MAX];
|
char cache_dir[FILE_MAX];
|
||||||
BLI_split_file_part(BKE_main_blendfile_path(disk_cache->bmain), main_name, sizeof(main_name));
|
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_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(
|
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_strncpy(path_version_file, path, sizeof(path_version_file));
|
||||||
BLI_path_append(path_version_file, sizeof(path_version_file), "cache_version");
|
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");
|
FILE *file = BLI_fopen(path_version_file, "r");
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user