Skip to content

Commit 0479138

Browse files
committed
Merge branch 'ed/fsmonitor-on-network-disk'
The built-in fsmonitor refuses to work on a network mounted repositories; a configuration knob for users to override this has been introduced. * ed/fsmonitor-on-network-disk: fsmonitor: option to allow fsmonitor to run against network-mounted repos
2 parents dd3f6c4 + 85dc0da commit 0479138

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

compat/fsmonitor/fsm-settings-win32.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,59 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
2424
return FSMONITOR_REASON_OK;
2525
}
2626

27+
/*
28+
* Check if monitoring remote working directories is allowed.
29+
*
30+
* By default, monitoring remote working directories is
31+
* disabled. Users may override this behavior in enviroments where
32+
* they have proper support.
33+
*/
34+
static int check_config_allowremote(struct repository *r)
35+
{
36+
int allow;
37+
38+
if (!repo_config_get_bool(r, "fsmonitor.allowremote", &allow))
39+
return allow;
40+
41+
return -1; /* fsmonitor.allowremote not set */
42+
}
43+
44+
/*
45+
* Check remote working directory protocol.
46+
*
47+
* Error if client machine cannot get remote protocol information.
48+
*/
49+
static int check_remote_protocol(wchar_t *wpath)
50+
{
51+
HANDLE h;
52+
FILE_REMOTE_PROTOCOL_INFO proto_info;
53+
54+
h = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
55+
FILE_FLAG_BACKUP_SEMANTICS, NULL);
56+
57+
if (h == INVALID_HANDLE_VALUE) {
58+
error(_("[GLE %ld] unable to open for read '%ls'"),
59+
GetLastError(), wpath);
60+
return -1;
61+
}
62+
63+
if (!GetFileInformationByHandleEx(h, FileRemoteProtocolInfo,
64+
&proto_info, sizeof(proto_info))) {
65+
error(_("[GLE %ld] unable to get protocol information for '%ls'"),
66+
GetLastError(), wpath);
67+
CloseHandle(h);
68+
return -1;
69+
}
70+
71+
CloseHandle(h);
72+
73+
trace_printf_key(&trace_fsmonitor,
74+
"check_remote_protocol('%ls') remote protocol %#8.8lx",
75+
wpath, proto_info.Protocol);
76+
77+
return 0;
78+
}
79+
2780
/*
2881
* Remote working directories are problematic for FSMonitor.
2982
*
@@ -76,6 +129,7 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
76129
*/
77130
static enum fsmonitor_reason check_remote(struct repository *r)
78131
{
132+
int ret;
79133
wchar_t wpath[MAX_PATH];
80134
wchar_t wfullpath[MAX_PATH];
81135
size_t wlen;
@@ -115,6 +169,20 @@ static enum fsmonitor_reason check_remote(struct repository *r)
115169
trace_printf_key(&trace_fsmonitor,
116170
"check_remote('%s') true",
117171
r->worktree);
172+
173+
ret = check_remote_protocol(wfullpath);
174+
if (ret < 0)
175+
return FSMONITOR_REASON_ERROR;
176+
177+
switch (check_config_allowremote(r)) {
178+
case 0: /* config overrides and disables */
179+
return FSMONITOR_REASON_REMOTE;
180+
case 1: /* config overrides and enables */
181+
return FSMONITOR_REASON_OK;
182+
default:
183+
break; /* config has no opinion */
184+
}
185+
118186
return FSMONITOR_REASON_REMOTE;
119187
}
120188

0 commit comments

Comments
 (0)