Re: [PATCH] commit: ensure correct permissions of the commit message
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 21, 2015, 01:31 UTC
- Message-ID
- <xmqq7fk8io3f.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20151220074559.GF30662@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 14 quoted lines
> So I don't have any real problem with this, but I suspect it's just the
> tip of the iceberg. We might want something like:
>
> FILE *fopen_shared(const char *path, const char *mode)
> {
> FILE *ret = fopen(path, mode);
> if (!ret)
> return NULL;
> if (adjust_shared_perm(path)) {
> fclose(ret);
> return NULL;
> }
> return ret;
> }Actually, we do not even _need_ a sharedness for this ephemeral file. The additional "adjust-shared-perm" is merely a workaround for the fact the next person cannot write into it when it is left behind, and because we do not want to remove it when we are done.
That does not measn that the next person cannot remove it when she finds there is a file there left behind. So alternatively, we could do something like this, perhaps?
FILE *fopen_forcibly(const char *path, const char *mode)
{
FILE *ret = fopen(path, mode); if (!ret && errno == EPERM) {
if (!unlink(path))
ret = fopen(path, mode);
else
errno = EPERM;
}
return ret;
}