From 51c6d2d3912fdc89e4389274f0e4fd724a427311 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 10 Aug 2018 13:15:21 -0500 Subject: [PATCH] storage: use rename instead of unlink, link, unlink --- src/storage.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/storage.c b/src/storage.c index fb728543..4bc056b2 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,6 +27,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -141,7 +142,6 @@ ssize_t write_file(const void *buffer, size_t len, goto error_mkostemps; r = TFR(write(fd, buffer, len)); - TFR(close(fd)); if (r != (ssize_t) len) { @@ -153,15 +153,15 @@ ssize_t write_file(const void *buffer, size_t len, * Now that the file contents are written, rename to the real * file name; this way we are uniquely sure that the whole * thing is there. + * conserve @r's value from 'write' */ - unlink(path); - /* conserve @r's value from 'write' */ - if (link(tmp_path, path) == -1) + if (rename(tmp_path, path) == -1) r = -1; error_write: - unlink(tmp_path); + if (r < 0) + unlink(tmp_path); error_mkostemps: error_create_dirs: l_free(tmp_path);