diff options
author | sfan5 <sfan5@live.de> | 2023-11-06 15:16:12 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-11-10 11:26:10 +0100 |
commit | b4e14b9420f1d419b3a32f287a8ff9d0911ebc85 (patch) | |
tree | 88f27d43e7e28c7ea0336a572d34ebe981c3a7e6 | |
parent | 8f8b63d6227e82da52f280f25d29f53fb30b7ecf (diff) | |
download | mpv-b4e14b9420f1d419b3a32f287a8ff9d0911ebc85.tar.bz2 mpv-b4e14b9420f1d419b3a32f287a8ff9d0911ebc85.tar.xz |
vo_gpu_next: overwrite cache files atomically
-rw-r--r-- | video/out/vo_gpu_next.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index 949f1e178e..dd70b0aaa2 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -1547,15 +1547,20 @@ static void save_cache_files(struct priv *p) if (!target_file) continue; - FILE *cache = fopen(target_file, "wb"); + char *tmp = talloc_asprintf(ta_ctx, "%s~", target_file); + FILE *cache = fopen(tmp, "wb"); if (!cache) continue; int ret = pl_cache_save_file(target_cache, cache); if (same_cache) ret += pl_cache_save_file(p->icc_cache, cache); fclose(cache); - if (ret < 0) + if (ret >= 0) + ret = rename(tmp, target_file); + if (ret < 0) { MP_WARN(p, "Failed saving cache to %s\n", target_file); + unlink(tmp); + } if (same_cache) break; |