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

Re: [RFC] test-lib.sh: No POSIXPERM for cygwin

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2013, 21:03 UTC
Message-ID
<7v620nhzle.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201303192049.58755.tboegi@web.de>
Torsten Bögershausen <tboegi@web.de> writes:
> Use a compile switch IGNORECYGWINFSTRICKS to disable the usage
> of cygwin_lstat_fn() only in path.c

The analysis of the problem and the basic idea to disable the fast-but-lying fstricks in the code that matters may be good, but the implementation is questionable.

What if we later need to move functions around, etc., so that some other calls in path.c still do want to use the fstricks bit while the existing ones in the file want the real lstat() information?

Actually, that already is the case. The call to lstat() in validate_headref() only cares about the S_ISXXX() type and can afford to use the fast-and-lying one, no?

How about doing something like this in the generic codepath, and implement your own cygwin_true_mode_bits() function at the cygwin compatibility layer, and add

    #define true_mode_bits cygwin_true_mode_bits

in the compat/cygwin.h file? The change has the documentation value to clarify what each lstat() is used for, too.

Ideally, the "#ifndef true_mode_bits" part may want to become a generic helper function if there are lstat() calls in other files that cygwin wants to use the real lstat() not the fast-but-lying one, but one step at a time.

Hrm?
 path.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/path.c b/path.c
index d3d3f8b..d0b31e5 100644
--- a/path.c
+++ b/path.c
@@ -14,6 +14,21 @@
 #include "strbuf.h"
 #include "string-list.h"
 
+#ifndef true_mode_bits
+/*
+ * The replacement lstat(2) we use on Cygwin is incomplete and
+ * lies about permission bits; most of the time we do not care,
+ * but the callsites of this wrpper do care.
+ */
+static int true_mode_bits(const char *path, int *mode)
+{
+	struct stat st;
+	if (lstat(path, &st) < 0)
+		return -1;
+	return st.st_mode;
+}
+#endif
+
 static char bad_path[] = "/bad-path/";
 
 static char *get_pathname(void)
@@ -400,9 +415,8 @@ int set_shared_perm(const char *path, int mode)
 		return 0;
 	}
 	if (!mode) {
-		if (lstat(path, &st) < 0)
+		if (true_mode_bits(path, &mode) < 0)
 			return -1;
-		mode = st.st_mode;
 		orig_mode = mode;
 	} else
 		orig_mode = 0;
Previous: Torsten BögershausenNext: Junio C Hamano
Message 2 of 3 in “Re: [RFC] test-lib.sh: No POSIXPERM for cygwin”
  1. Torsten BögershausenMar 19, 2013
  2. Junio C HamanoMar 19, 2013
  3. Junio C HamanoMar 19, 2013

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.