Skip to content

Commit

Permalink
compat/fsmonitor/fsm-*-win32: support long paths
Browse files Browse the repository at this point in the history
Update wchar_t buffers to use MAX_LONG_PATH instead of MAX_PATH and call
xutftowcs_long_path() in the Win32 backend source files.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Sep 18, 2024
1 parent 2a1b191 commit 12a0a6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions compat/fsmonitor/fsm-health-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct fsm_health_data

struct wt_moved
{
wchar_t wpath[MAX_PATH + 1];
wchar_t wpath[MAX_LONG_PATH + 1];
BY_HANDLE_FILE_INFORMATION bhfi;
} wt_moved;
};
Expand Down Expand Up @@ -143,8 +143,8 @@ static int has_worktree_moved(struct fsmonitor_daemon_state *state,
return 0;

case CTX_INIT:
if (xutftowcs_path(data->wt_moved.wpath,
state->path_worktree_watch.buf) < 0) {
if (xutftowcs_long_path(data->wt_moved.wpath,
state->path_worktree_watch.buf) < 0) {
error(_("could not convert to wide characters: '%s'"),
state->path_worktree_watch.buf);
return -1;
Expand Down
18 changes: 9 additions & 9 deletions compat/fsmonitor/fsm-listen-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct one_watch
DWORD count;

struct strbuf path;
wchar_t wpath_longname[MAX_PATH + 1];
wchar_t wpath_longname[MAX_LONG_PATH + 1];
DWORD wpath_longname_len;

HANDLE hDir;
Expand Down Expand Up @@ -131,8 +131,8 @@ static int normalize_path_in_utf8(wchar_t *wpath, DWORD wpath_len,
*/
static void check_for_shortnames(struct one_watch *watch)
{
wchar_t buf_in[MAX_PATH + 1];
wchar_t buf_out[MAX_PATH + 1];
wchar_t buf_in[MAX_LONG_PATH + 1];
wchar_t buf_out[MAX_LONG_PATH + 1];
wchar_t *last;
wchar_t *p;

Expand Down Expand Up @@ -197,8 +197,8 @@ static enum get_relative_result get_relative_longname(
const wchar_t *wpath, DWORD wpath_len,
wchar_t *wpath_longname, size_t bufsize_wpath_longname)
{
wchar_t buf_in[2 * MAX_PATH + 1];
wchar_t buf_out[MAX_PATH + 1];
wchar_t buf_in[2 * MAX_LONG_PATH + 1];
wchar_t buf_out[MAX_LONG_PATH + 1];
DWORD root_len;
DWORD out_len;

Expand Down Expand Up @@ -298,10 +298,10 @@ static struct one_watch *create_watch(const char *path)
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
HANDLE hDir;
DWORD len_longname;
wchar_t wpath[MAX_PATH + 1];
wchar_t wpath_longname[MAX_PATH + 1];
wchar_t wpath[MAX_LONG_PATH + 1];
wchar_t wpath_longname[MAX_LONG_PATH + 1];

if (xutftowcs_path(wpath, path) < 0) {
if (xutftowcs_long_path(wpath, path) < 0) {
error(_("could not convert to wide characters: '%s'"), path);
return NULL;
}
Expand Down Expand Up @@ -545,7 +545,7 @@ static int process_worktree_events(struct fsmonitor_daemon_state *state)
struct string_list cookie_list = STRING_LIST_INIT_DUP;
struct fsmonitor_batch *batch = NULL;
const char *p = watch->buffer;
wchar_t wpath_longname[MAX_PATH + 1];
wchar_t wpath_longname[MAX_LONG_PATH + 1];

/*
* If the kernel gets more events than will fit in the kernel
Expand Down
8 changes: 4 additions & 4 deletions compat/fsmonitor/fsm-path-utils-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ static int check_remote_protocol(wchar_t *wpath)
*/
int fsmonitor__get_fs_info(const char *path, struct fs_info *fs_info)
{
wchar_t wpath[MAX_PATH];
wchar_t wfullpath[MAX_PATH];
wchar_t wpath[MAX_LONG_PATH];
wchar_t wfullpath[MAX_LONG_PATH];
size_t wlen;
UINT driveType;

/*
* Do everything in wide chars because the drive letter might be
* a multi-byte sequence. See win32_has_dos_drive_prefix().
*/
if (xutftowcs_path(wpath, path) < 0) {
if (xutftowcs_long_path(wpath, path) < 0) {
return -1;
}

Expand All @@ -97,7 +97,7 @@ int fsmonitor__get_fs_info(const char *path, struct fs_info *fs_info)
* slashes to backslashes. This is essential to get GetDriveTypeW()
* correctly handle some UNC "\\server\share\..." paths.
*/
if (!GetFullPathNameW(wpath, MAX_PATH, wfullpath, NULL)) {
if (!GetFullPathNameW(wpath, MAX_LONG_PATH, wfullpath, NULL)) {
return -1;
}

Expand Down

0 comments on commit 12a0a6f

Please sign in to comment.