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

Re: permissions

From
William Pursell <bill.pursell@gmail.com>
Date
Jun 8, 2010, 10:25 UTC
Message-ID
<4C0E1AB1.2030702@wpursell.net>
In-Reply-To
<7vvd9wvswy.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 6 quoted lines
> I think it is sane to abort with "permission denied", as it is "not a git
> repository" but it is "we cannot even determine if that .git we see is a
> git repository, and if it is, then we cannot do any git operation here as
> we cannot read it".  As to what you call "the current work flow", I think
> it is not like we _support_ such usage, but more like it _happens to_ work
> that way.

Here's a patch. This doesn't address the issue of a damaged repository, but just catches access errors and permissions.

>From 8f1c8f4d572fe62a26d1fca47abc976e78942697 Mon Sep 17 00:00:00 2001
From: William Pursell <bill.pursell@gmail.com>
Date: Tue, 8 Jun 2010 00:16:43 -1000
Subject: [PATCH] Terminate on access errors

This changes the way git finds a repository. Previously, if access is denied to .git (or $GIT_DIR), git will use the object directory in a higher level directory. With this patch, git will instead terminate and emit an error message indicating the access failure. Also, other errors (such as soft-link loops in GIT_OBJECT_DIRECTORIES) will cause termination.

Signed-off-by: William Pursell <bill.pursell@gmail.com>
---
 setup.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/setup.c b/setup.c
index 7e04602..a53331c 100644
--- a/setup.c
+++ b/setup.c
@@ -155,6 +155,18 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
 }

 /*
+ * Wrapper around access that terminates on
+ * errors other than ENOENT.
+ */
+static int xaccess(const char *path, int amode)
+{
+	int status = access(path, amode);
+	if (status && errno != ENOENT)
+		die_errno("%s", path);
+	return status;
+}
+
+/*
  * Test if it looks like we're at a git directory.
  * We want to see:
  *
@@ -172,17 +184,17 @@ static int is_git_directory(const char *suspect)

 	strcpy(path, suspect);
 	if (getenv(DB_ENVIRONMENT)) {
-		if (access(getenv(DB_ENVIRONMENT), X_OK))
+		if (xaccess(getenv(DB_ENVIRONMENT), X_OK))
 			return 0;
 	}
 	else {
 		strcpy(path + len, "/objects");
-		if (access(path, X_OK))
+		if (xaccess(path, X_OK))
 			return 0;
 	}

 	strcpy(path + len, "/refs");
-	if (access(path, X_OK))
+	if (xaccess(path, X_OK))
 		return 0;

 	strcpy(path + len, "/HEAD");
-- 
1.7.1.245.g7c42e.dirty



-- 
William Pursell
Previous: Junio C HamanoNext: Alex Riesen
Message 8 of 17 in “permissions”
  1. William PursellJun 5, 2010
  2. Andreas SchwabJun 5, 2010
  3. William PursellJun 5, 2010
  4. Alex RiesenJun 6, 2010
  5. William PursellJun 6, 2010
  6. Alex RiesenJun 6, 2010
  7. Junio C HamanoJun 6, 2010
  8. William PursellJun 8, 2010
  9. Alex RiesenJun 8, 2010
  10. Junio C HamanoJun 8, 2010
  11. William PursellJun 8, 2010
  12. Alex RiesenJun 9, 2010
  13. William PursellJun 9, 2010
  14. Thomas RastJun 9, 2010
  15. Alex RiesenJun 9, 2010
  16. Alex RiesenJun 9, 2010
  17. Steven MichalskeJun 9, 2010

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.