Torsten Bögershausen <> 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.


 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;
 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;
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to