3 #include "fsmonitor-path-utils.h"
6 * Check remote working directory protocol.
8 * Return -1 if client machine cannot get remote protocol information.
10 static int check_remote_protocol(wchar_t *wpath
)
13 FILE_REMOTE_PROTOCOL_INFO proto_info
;
15 h
= CreateFileW(wpath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
16 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
18 if (h
== INVALID_HANDLE_VALUE
) {
19 error(_("[GLE %ld] unable to open for read '%ls'"),
20 GetLastError(), wpath
);
24 if (!GetFileInformationByHandleEx(h
, FileRemoteProtocolInfo
,
25 &proto_info
, sizeof(proto_info
))) {
26 error(_("[GLE %ld] unable to get protocol information for '%ls'"),
27 GetLastError(), wpath
);
34 trace_printf_key(&trace_fsmonitor
,
35 "check_remote_protocol('%ls') remote protocol %#8.8lx",
36 wpath
, proto_info
.Protocol
);
44 * (a) Windows allows a network share to be mapped to a drive letter.
45 * (This is the normal method to access it.)
47 * $ NET USE Z: \\server\share
48 * $ git -C Z:/repo status
50 * (b) Windows allows a network share to be referenced WITHOUT mapping
53 * $ NET USE \\server\share\dir
54 * $ git -C //server/share/repo status
56 * (c) Windows allows "SUBST" to create a fake drive mapping to an
57 * arbitrary path (which may be remote)
62 * (d) Windows allows a directory symlink to be created on a local
63 * file system that points to a remote repo.
65 * $ mklink /d ./link //server/share/repo
66 * $ git -C ./link status
68 int fsmonitor__get_fs_info(const char *path
, struct fs_info
*fs_info
)
70 wchar_t wpath
[MAX_PATH
];
71 wchar_t wfullpath
[MAX_PATH
];
76 * Do everything in wide chars because the drive letter might be
77 * a multi-byte sequence. See win32_has_dos_drive_prefix().
79 if (xutftowcs_path(wpath
, path
) < 0) {
84 * GetDriveTypeW() requires a final slash. We assume that the
85 * worktree pathname points to an actual directory.
88 if (wpath
[wlen
- 1] != L
'\\' && wpath
[wlen
- 1] != L
'/') {
89 wpath
[wlen
++] = L
'\\';
94 * Normalize the path. If nothing else, this converts forward
95 * slashes to backslashes. This is essential to get GetDriveTypeW()
96 * correctly handle some UNC "\\server\share\..." paths.
98 if (!GetFullPathNameW(wpath
, MAX_PATH
, wfullpath
, NULL
)) {
102 driveType
= GetDriveTypeW(wfullpath
);
103 trace_printf_key(&trace_fsmonitor
,
104 "DriveType '%s' L'%ls' (%u)",
105 path
, wfullpath
, driveType
);
107 if (driveType
== DRIVE_REMOTE
) {
108 fs_info
->is_remote
= 1;
109 if (check_remote_protocol(wfullpath
) < 0)
112 fs_info
->is_remote
= 0;
115 trace_printf_key(&trace_fsmonitor
,
116 "'%s' is_remote: %d",
117 path
, fs_info
->is_remote
);
122 int fsmonitor__is_fs_remote(const char *path
)
125 if (fsmonitor__get_fs_info(path
, &fs
))
133 int fsmonitor__get_alias(const char *path
, struct alias_info
*info
)
141 char *fsmonitor__resolve_alias(const char *path
,
142 const struct alias_info
*info
)