aboutsummaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-09-13 11:38:22 -0700
committerJunio C Hamano <gitster@pobox.com>2022-09-13 11:38:23 -0700
commit04791386457e48220ee4388b9b3b51e36203d8c1 (patch)
treea8be9eca028b52365210dbf08faf3a3833e3a85a /compat
parentdd3f6c4cae7e3b15ce984dce8593ff7569650e24 (diff)
parent85dc0da6dcf21801149e747310d087abe26b2354 (diff)
downloadgit-04791386457e48220ee4388b9b3b51e36203d8c1.tar.gz
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
Diffstat (limited to 'compat')
-rw-r--r--compat/fsmonitor/fsm-settings-win32.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index 907655720b..e5ec5b0a9f 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -25,6 +25,59 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
}
/*
+ * Check if monitoring remote working directories is allowed.
+ *
+ * By default, monitoring remote working directories is
+ * disabled. Users may override this behavior in enviroments where
+ * they have proper support.
+ */
+static int check_config_allowremote(struct repository *r)
+{
+ int allow;
+
+ if (!repo_config_get_bool(r, "fsmonitor.allowremote", &allow))
+ return allow;
+
+ return -1; /* fsmonitor.allowremote not set */
+}
+
+/*
+ * Check remote working directory protocol.
+ *
+ * Error if client machine cannot get remote protocol information.
+ */
+static int check_remote_protocol(wchar_t *wpath)
+{
+ HANDLE h;
+ FILE_REMOTE_PROTOCOL_INFO proto_info;
+
+ h = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, NULL);
+
+ if (h == INVALID_HANDLE_VALUE) {
+ error(_("[GLE %ld] unable to open for read '%ls'"),
+ GetLastError(), wpath);
+ return -1;
+ }
+
+ if (!GetFileInformationByHandleEx(h, FileRemoteProtocolInfo,
+ &proto_info, sizeof(proto_info))) {
+ error(_("[GLE %ld] unable to get protocol information for '%ls'"),
+ GetLastError(), wpath);
+ CloseHandle(h);
+ return -1;
+ }
+
+ CloseHandle(h);
+
+ trace_printf_key(&trace_fsmonitor,
+ "check_remote_protocol('%ls') remote protocol %#8.8lx",
+ wpath, proto_info.Protocol);
+
+ return 0;
+}
+
+/*
* Remote working directories are problematic for FSMonitor.
*
* The underlying file system on the server machine and/or the remote
@@ -76,6 +129,7 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
*/
static enum fsmonitor_reason check_remote(struct repository *r)
{
+ int ret;
wchar_t wpath[MAX_PATH];
wchar_t wfullpath[MAX_PATH];
size_t wlen;
@@ -115,6 +169,20 @@ static enum fsmonitor_reason check_remote(struct repository *r)
trace_printf_key(&trace_fsmonitor,
"check_remote('%s') true",
r->worktree);
+
+ ret = check_remote_protocol(wfullpath);
+ if (ret < 0)
+ return FSMONITOR_REASON_ERROR;
+
+ switch (check_config_allowremote(r)) {
+ case 0: /* config overrides and disables */
+ return FSMONITOR_REASON_REMOTE;
+ case 1: /* config overrides and enables */
+ return FSMONITOR_REASON_OK;
+ default:
+ break; /* config has no opinion */
+ }
+
return FSMONITOR_REASON_REMOTE;
}