git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Problem with git-push

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 2, 2006, 09:29 UTC
Message-ID
<Pine.LNX.4.63.0611021018040.1670@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vk62f2l46.fsf@assigned-by-dhcp.cox.net>
Hi,
On Wed, 1 Nov 2006, Junio C Hamano wrote:
Show 12 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > How about this instead:
> >
> > -		mkdir(filename, 0777);
> > -		if (adjust_shared_perm(filename))
> > +		if (!mkdir(filename, 0777) && adjust_shared_perm(filename)) {
> > +			*dir = '/';
> >  			return -2;
> > +		}
> 
> Not really.  See the comment above the code you just touched.
 /*
  * Try to mkdir the last path component if that failed.
  *
  * Re-try the "link()" regardless of whether the mkdir
  * succeeds, since a race might mean that somebody
  * else succeeded.
  */

What I proposed does not break that. It only means that you only try to adjust the permissions if the mkdir succeeded. If somebody else created the directory in the mean time, it is not our job to adjust the permissions. Worse, if the other mkdir was run by a different user, the permission adjusting _cannot_ succeed, like you pointed out.

So I think that my patch is correct, but does not matter very much.

The other thing you asked for: adjust_shared_permissions should only try to adjust the permissions only if they are not already correct. Here is my attempt to implement that:

Totally untested.

Ciao, Dscho

-- snip -- adjust_shared_perm(): Avoid unnecessary chmod()s

Sighed-off-by: Johannes E. Schindelin <johannes.schindelin@gmx.de>
---
diff --git a/path.c b/path.c
index bb89fb0..0a2bc51 100644
--- a/path.c
+++ b/path.c
@@ -279,7 +279,7 @@ int adjust_shared_perm(const char *path)
 			    : 0));
 	if (S_ISDIR(mode))
 		mode |= S_ISGID;
-	if (chmod(path, mode) < 0)
+	if ((mode & st.st_mode != mode) && chmod(path, mode) < 0)
 		return -2;
 	return 0;
 }
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 12 in “Problem with git-push”
  1. Florent ThoumieOct 31, 2006
  2. Junio C HamanoOct 31, 2006
  3. Johannes SchindelinNov 1, 2006
  4. Junio C HamanoNov 1, 2006
  5. Junio C HamanoNov 1, 2006
  6. Florent ThoumieNov 1, 2006
  7. Junio C HamanoNov 1, 2006
  8. Johannes SchindelinNov 2, 2006
  9. Junio C HamanoNov 1, 2006
  10. Johannes SchindelinNov 2, 2006
  11. Junio C HamanoNov 3, 2006
  12. Florent ThoumieNov 1, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.