diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2018-04-25 20:11:33 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2018-05-16 13:24:01 +0200 |
| commit | b23116112e21fbdecc51e2029bfe01c0f19b5267 (patch) | |
| tree | c583f45ecedad34f6e589acfef2b18669b64c8fd /text.c | |
| parent | 3f31e37f488e7f063d6d341011facf1c59092287 (diff) | |
| download | vis-b23116112e21fbdecc51e2029bfe01c0f19b5267.tar.gz vis-b23116112e21fbdecc51e2029bfe01c0f19b5267.tar.xz | |
text: do not unlink existing `file~` when saving to `file`
Fail atomic save if temporary file already exists. A follow up
commit will use `mkstemp(3)` for temporary file creation.
Diffstat (limited to 'text.c')
| -rw-r--r-- | text.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -849,7 +849,7 @@ static bool text_save_begin_atomic(TextSave *ctx) { goto err; snprintf(ctx->tmpname, namelen, "%s~", ctx->filename); - if ((ctx->fd = open(ctx->tmpname, O_CREAT|O_WRONLY|O_TRUNC, oldfd == -1 ? 0666 : oldmeta.st_mode)) == -1) + if ((ctx->fd = open(ctx->tmpname, O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, oldfd == -1 ? 0666 : oldmeta.st_mode)) == -1) goto err; if (oldfd != -1) { if (!preserve_acl(oldfd, ctx->fd) || !preserve_selinux_context(oldfd, ctx->fd)) @@ -873,6 +873,8 @@ err: if (ctx->fd != -1) close(ctx->fd); ctx->fd = -1; + free(ctx->tmpname); + ctx->tmpname = NULL; errno = saved_errno; return false; } |
