diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-18 15:49:56 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-18 15:49:56 +0200 |
| commit | 7eca0d08630e01f58fb2e5928442b0bdd0146777 (patch) | |
| tree | e8248f92c394d01af288ae339566810bc32aceb4 /text.c | |
| parent | 3f33deadfc84e837d9e2e7d347186f665ca1fb15 (diff) | |
| download | vis-7eca0d08630e01f58fb2e5928442b0bdd0146777.tar.gz vis-7eca0d08630e01f58fb2e5928442b0bdd0146777.tar.xz | |
text: when saving also fsync(2) the destination directory after rename(2)
Diffstat (limited to 'text.c')
| -rw-r--r-- | text.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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; |
