vis

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

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

commit d8f380b33063c8075ff4af4ae71468b9436ec6b9
parent 5ab58f5633010524c6a2c85e87c03c8b79998f5d
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 27 Feb 2017 11:14:42 -0800

Honor user's umask when saving files

If the user wants new files to be created as 600, they will have set
their umask to 077 in their environment. vis shouldn't restrict this
further than the user has configured.

Diffstat:
Mtext.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/text.c b/text.c @@ -856,7 +856,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 ? S_IRUSR|S_IWUSR : oldmeta.st_mode)) == -1) + if ((ctx->fd = open(ctx->tmpname, O_CREAT|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)) @@ -924,7 +924,7 @@ static bool text_save_begin_inplace(TextSave *ctx) { Text *txt = ctx->txt; struct stat meta = { 0 }; int newfd = -1, saved_errno; - if ((ctx->fd = open(ctx->filename, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR)) == -1) + if ((ctx->fd = open(ctx->filename, 0666, S_IRUSR|S_IWUSR)) == -1) goto err; if (fstat(ctx->fd, &meta) == -1) goto err;