3 #include "fsmonitor-path-utils.h"
7 * Check remote working directory protocol.
9 * Return -1 if client machine cannot get remote protocol information.
11 static int check_remote_protocol(wchar_t *wpath
)
14 FILE_REMOTE_PROTOCOL_INFO proto_info
;
16 h
= CreateFileW(wpath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
17 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
19 if (h
== INVALID_HANDLE_VALUE
) {
20 error(_("[GLE %ld] unable to open for read '%ls'"),
21 GetLastError(), wpath
);
25 if (!GetFileInformationByHandleEx(h
, FileRemoteProtocolInfo
,
26 &proto_info
, sizeof(proto_info
))) {
27 error(_("[GLE %ld] unable to get protocol information for '%ls'"),
28 GetLastError(), wpath
);
35 trace_printf_key(&trace_fsmonitor
,
36 "check_remote_protocol('%ls') remote protocol %#8.8lx",
37 wpath
, proto_info
.Protocol
);
45 * (a) Windows allows a network share to be mapped to a drive letter.
46 * (This is the normal method to access it.)
48 * $ NET USE Z: \\server\share
49 * $ git -C Z:/repo status
51 * (b) Windows allows a network share to be referenced WITHOUT mapping
54 * $ NET USE \\server\share\dir
55 * $ git -C //server/share/repo status
57 * (c) Windows allows "SUBST" to create a fake drive mapping to an
58 * arbitrary path (which may be remote)
63 * (d) Windows allows a directory symlink to be created on a local
64 * file system that points to a remote repo.
66 * $ mklink /d ./link //server/share/repo
67 * $ git -C ./link status
69 int fsmonitor__get_fs_info(const char *path
, struct fs_info
*fs_info
)
71 wchar_t wpath
[MAX_PATH
];
72 wchar_t wfullpath
[MAX_PATH
];
77 * Do everything in wide chars because the drive letter might be
78 * a multi-byte sequence. See win32_has_dos_drive_prefix().
80 if (xutftowcs_path(wpath
, path
) < 0) {
85 * GetDriveTypeW() requires a final slash. We assume that the
86 * worktree pathname points to an actual directory.
89 if (wpath
[wlen
- 1] != L
'\\' && wpath
[wlen
- 1] != L
'/') {
90 wpath
[wlen
++] = L
'\\';
95 * Normalize the path. If nothing else, this converts forward
96 * slashes to backslashes. This is essential to get GetDriveTypeW()
97 * correctly handle some UNC "\\server\share\..." paths.
99 if (!GetFullPathNameW(wpath
, MAX_PATH
, wfullpath
, NULL
)) {
103 driveType
= GetDriveTypeW(wfullpath
);
104 trace_printf_key(&trace_fsmonitor
,
105 "DriveType '%s' L'%ls' (%u)",
106 path
, wfullpath
, driveType
);
108 if (driveType
== DRIVE_REMOTE
) {
109 fs_info
->is_remote
= 1;
110 if (check_remote_protocol(wfullpath
) < 0)
113 fs_info
->is_remote
= 0;
116 trace_printf_key(&trace_fsmonitor
,
117 "'%s' is_remote: %d",
118 path
, fs_info
->is_remote
);
123 int fsmonitor__is_fs_remote(const char *path
)
126 if (fsmonitor__get_fs_info(path
, &fs
))
134 int fsmonitor__get_alias(const char *path
, struct alias_info
*info
)
142 char *fsmonitor__resolve_alias(const char *path
,
143 const struct alias_info
*info
)