Skip to content

Commit 0117c2f

Browse files
tboegigitster
authored andcommitted
Make core.sharedRepository work under cygwin 1.7
When core.sharedRepository is used, set_shared_perm() in path.c needs lstat() to return the correct POSIX permissions. The default for cygwin is core.ignoreCygwinFSTricks = false, which means that the fast implementation in do_stat() is used instead of lstat(). lstat() under cygwin uses the Windows security model to implement POSIX-like permissions. The user, group or everyone bits can be set individually. do_stat() simplifes the file permission bits, and may return a wrong value. The read-only attribute of a file is used to calculate the permissions, resulting in either rw-r--r-- or r--r--r-- One effect of the simplified do_stat() is that t1301 fails. Add a function cygwin_get_st_mode_bits() which returns the POSIX permissions. When not compiling for cygwin, true_mode_bits() in path.c is used. Side note: t1301 passes under cygwin 1.5. The "user write" bit is synchronized with the "read only" attribute of a file: $ chmod 444 x $ attrib x A R C:\temp\pt\x cygwin 1.7 would show A C:\temp\pt\x Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b592fa commit 0117c2f

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

compat/cygwin.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define CYGWIN_C
12
#define WIN32_LEAN_AND_MEAN
23
#ifdef CYGWIN_V15_WIN32API
34
#include "../git-compat-util.h"
@@ -10,6 +11,18 @@
1011
#endif
1112
#include "../cache.h" /* to read configuration */
1213

14+
/*
15+
* Return POSIX permission bits, regardless of core.ignorecygwinfstricks
16+
*/
17+
int cygwin_get_st_mode_bits(const char *path, int *mode)
18+
{
19+
struct stat st;
20+
if (lstat(path, &st) < 0)
21+
return -1;
22+
*mode = st.st_mode;
23+
return 0;
24+
}
25+
1326
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
1427
{
1528
long long winTime = ((long long)ft->dwHighDateTime << 32) +

compat/cygwin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
typedef int (*stat_fn_t)(const char*, struct stat*);
55
extern stat_fn_t cygwin_stat_fn;
66
extern stat_fn_t cygwin_lstat_fn;
7+
int cygwin_get_st_mode_bits(const char *path, int *mode);
78

9+
#define get_st_mode_bits(p,m) cygwin_get_st_mode_bits((p),(m))
10+
#ifndef CYGWIN_C
11+
/* cygwin.c needs the original lstat() */
812
#define stat(path, buf) (*cygwin_stat_fn)(path, buf)
913
#define lstat(path, buf) (*cygwin_lstat_fn)(path, buf)
14+
#endif

git-compat-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
typedef long intptr_t;
164164
typedef unsigned long uintptr_t;
165165
#endif
166+
int get_st_mode_bits(const char *path, int *mode);
166167
#if defined(__CYGWIN__)
167168
#undef _XOPEN_SOURCE
168169
#include <grp.h>

path.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
#include "strbuf.h"
1515
#include "string-list.h"
1616

17+
#ifndef get_st_mode_bits
18+
/*
19+
* The replacement lstat(2) we use on Cygwin is incomplete and
20+
* may return wrong permission bits. Most of the time we do not care,
21+
* but the callsites of this wrapper do care.
22+
*/
23+
int get_st_mode_bits(const char *path, int *mode)
24+
{
25+
struct stat st;
26+
if (lstat(path, &st) < 0)
27+
return -1;
28+
*mode = st.st_mode;
29+
return 0;
30+
}
31+
#endif
32+
1733
static char bad_path[] = "/bad-path/";
1834

1935
static char *get_pathname(void)
@@ -391,7 +407,6 @@ const char *enter_repo(const char *path, int strict)
391407

392408
int set_shared_perm(const char *path, int mode)
393409
{
394-
struct stat st;
395410
int tweak, shared, orig_mode;
396411

397412
if (!shared_repository) {
@@ -400,9 +415,8 @@ int set_shared_perm(const char *path, int mode)
400415
return 0;
401416
}
402417
if (!mode) {
403-
if (lstat(path, &st) < 0)
418+
if (get_st_mode_bits(path, &mode) < 0)
404419
return -1;
405-
mode = st.st_mode;
406420
orig_mode = mode;
407421
} else
408422
orig_mode = 0;

0 commit comments

Comments
 (0)