aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-18 15:49:56 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-18 15:49:56 +0200
commit7eca0d08630e01f58fb2e5928442b0bdd0146777 (patch)
treee8248f92c394d01af288ae339566810bc32aceb4
parent3f33deadfc84e837d9e2e7d347186f665ca1fb15 (diff)
downloadvis-7eca0d08630e01f58fb2e5928442b0bdd0146777.tar.gz
vis-7eca0d08630e01f58fb2e5928442b0bdd0146777.tar.xz
text: when saving also fsync(2) the destination directory after rename(2)
-rw-r--r--text.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/text.c b/text.c
index 9358c9a..ef561d5 100644
--- a/text.c
+++ b/text.c
@@ -7,6 +7,7 @@
#include <errno.h>
#include <wchar.h>
#include <stdint.h>
+#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -893,7 +894,7 @@ static bool text_save_commit_atomic(TextSave *ctx) {
if (fstat(ctx->fd, &meta) == -1)
return false;
- bool close_failed = close(ctx->fd) == -1;
+ bool close_failed = (close(ctx->fd) == -1);
ctx->fd = -1;
if (close_failed)
return false;
@@ -901,6 +902,21 @@ static bool text_save_commit_atomic(TextSave *ctx) {
if (rename(ctx->tmpname, ctx->filename) == -1)
return false;
+ free(ctx->tmpname);
+ ctx->tmpname = NULL;
+
+ int dir = open(dirname(ctx->filename), O_DIRECTORY|O_RDONLY);
+ if (dir == -1)
+ return false;
+
+ if (fsync(dir) == -1) {
+ close(dir);
+ return false;
+ }
+
+ if (close(dir) == -1)
+ return false;
+
if (meta.st_mtime)
ctx->txt->info = meta;
return true;