1 #include "git-compat-util.h"
2 #include "fsmonitor-ll.h"
3 #include "fsmonitor-path-utils.h"
8 * Check remote working directory protocol.
10 * Return -1 if client machine cannot get remote protocol information.
12 static int check_remote_protocol(wchar_t *wpath
)
15 FILE_REMOTE_PROTOCOL_INFO proto_info
;
17 h
= CreateFileW(wpath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
18 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
20 if (h
== INVALID_HANDLE_VALUE
) {
21 error(_("[GLE %ld] unable to open for read '%ls'"),
22 GetLastError(), wpath
);
26 if (!GetFileInformationByHandleEx(h
, FileRemoteProtocolInfo
,
27 &proto_info
, sizeof(proto_info
))) {
28 error(_("[GLE %ld] unable to get protocol information for '%ls'"),
29 GetLastError(), wpath
);
36 trace_printf_key(&trace_fsmonitor
,
37 "check_remote_protocol('%ls') remote protocol %#8.8lx",
38 wpath
, proto_info
.Protocol
);
46 * (a) Windows allows a network share to be mapped to a drive letter.
47 * (This is the normal method to access it.)
49 * $ NET USE Z: \\server\share
50 * $ git -C Z:/repo status
52 * (b) Windows allows a network share to be referenced WITHOUT mapping
55 * $ NET USE \\server\share\dir
56 * $ git -C //server/share/repo status
58 * (c) Windows allows "SUBST" to create a fake drive mapping to an
59 * arbitrary path (which may be remote)
64 * (d) Windows allows a directory symlink to be created on a local
65 * file system that points to a remote repo.
67 * $ mklink /d ./link //server/share/repo
68 * $ git -C ./link status
70 int fsmonitor__get_fs_info(const char *path
, struct fs_info
*fs_info
)
72 wchar_t wpath
[MAX_PATH
];
73 wchar_t wfullpath
[MAX_PATH
];
78 * Do everything in wide chars because the drive letter might be
79 * a multi-byte sequence. See win32_has_dos_drive_prefix().
81 if (xutftowcs_path(wpath
, path
) < 0) {
86 * GetDriveTypeW() requires a final slash. We assume that the
87 * worktree pathname points to an actual directory.
90 if (wpath
[wlen
- 1] != L
'\\' && wpath
[wlen
- 1] != L
'/') {
91 wpath
[wlen
++] = L
'\\';
96 * Normalize the path. If nothing else, this converts forward
97 * slashes to backslashes. This is essential to get GetDriveTypeW()
98 * correctly handle some UNC "\\server\share\..." paths.
100 if (!GetFullPathNameW(wpath
, MAX_PATH
, wfullpath
, NULL
)) {
104 driveType
= GetDriveTypeW(wfullpath
);
105 trace_printf_key(&trace_fsmonitor
,
106 "DriveType '%s' L'%ls' (%u)",
107 path
, wfullpath
, driveType
);
109 if (driveType
== DRIVE_REMOTE
) {
110 fs_info
->is_remote
= 1;
111 if (check_remote_protocol(wfullpath
) < 0)
114 fs_info
->is_remote
= 0;
117 trace_printf_key(&trace_fsmonitor
,
118 "'%s' is_remote: %d",
119 path
, fs_info
->is_remote
);
124 int fsmonitor__is_fs_remote(const char *path
)
127 if (fsmonitor__get_fs_info(path
, &fs
))
135 int fsmonitor__get_alias(const char *path UNUSED
,
136 struct alias_info
*info UNUSED
)
144 char *fsmonitor__resolve_alias(const char *path UNUSED
,
145 const struct alias_info
*info UNUSED
)