vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit c942b61df0f1b881413d95e3fc2117c9223426e0
parent a046c9d54d87d2ea926aa012d036ae3c6f7b2550
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 18 Apr 2016 15:49:56 +0200

text: when saving also fsync(2) the destination directory after rename(2)

Diffstat:
Mtext.c | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git 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;