Re: [PATCH] commit: ensure correct permissions of the commit message

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] commit: ensure correct permissions of the commit message

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:07:32

Jeff King [off-list ref] writes:
On Sun, Dec 20, 2015 at 05:31:48PM -0800, Junio C Hamano wrote:
quoted
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;
        }
Yeah, I think that is a much nicer solution for this case. It should
work even in a shared repo, since we set the permissions for the
surrounding $GIT_DIR appropriately[1].

I guess it would not apply to any files that do not want to truncate the
existing contents. Probably it should drop the "mode" parameter at all,
since anything but "w" would be crazy?
Absolutely.  Thanks for spotting.

Re: [PATCH] commit: ensure correct permissions of the commit message

From: Johannes Schindelin <hidden>
Date: 2016-06-15 23:07:36

Hi,

On Mon, 21 Dec 2015, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
On Sun, Dec 20, 2015 at 05:31:48PM -0800, Junio C Hamano wrote:
quoted
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;
        }
Yeah, I think that is a much nicer solution for this case. It should
work even in a shared repo, since we set the permissions for the
surrounding $GIT_DIR appropriately[1].

I guess it would not apply to any files that do not want to truncate the
existing contents. Probably it should drop the "mode" parameter at all,
since anything but "w" would be crazy?
Absolutely.  Thanks for spotting.
So maybe

	fcreate_or_truncate(const char *path)
	{
		 FILE *ret = fopen(path, "w");

		 if (!ret && errno == EPERM) {
			 if (!unlink(path))
				 ret = fopen(path, "w");
			 else
				 errno = EPERM;
		 }
		 return ret;
	 }

?

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help