diff options
author | Grazvydas Ignotas <[email protected]> | 2017-03-18 22:58:55 +0200 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-03-20 08:24:46 +1100 |
commit | 274aaa331c969b998d5cf3f62015124297147ada (patch) | |
tree | b7c436aaf0a22491d45072f5c513472c75ba2a0a /src/util | |
parent | 67911fa4b88aedc709a92c1630c1de9ea3a30d1f (diff) |
util/disk_cache: check rename result
I haven't seen this causing problems in practice, but for correctness
we should also check if rename succeeded to avoid breaking accounting
and leaving a .tmp file behind.
Signed-off-by: Grazvydas Ignotas <[email protected]>
Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/disk_cache.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index 36b27d95ede..d7e1996c41b 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -878,7 +878,11 @@ cache_put(void *job, int thread_index) unlink(filename_tmp); goto done; } - rename(filename_tmp, filename); + ret = rename(filename_tmp, filename); + if (ret == -1) { + unlink(filename_tmp); + goto done; + } file_size += cf_data_size; p_atomic_add(dc_job->cache->size, file_size); @@ -886,7 +890,7 @@ cache_put(void *job, int thread_index) done: if (fd_final != -1) close(fd_final); - /* This close finally releases the flock, (now that the final dile + /* This close finally releases the flock, (now that the final file * has been renamed into place and the size has been added). */ if (fd != -1) |