Issue #3819: G_FILE_MONITOR_WATCH_HARD_LINK does not monitor files on Windows.

Current code was clearly considering the case of having only a filename
as a directory monitoring, instead of a hard-link monitoring. As I
assume that hard links don't exist on Windows, this case should simply
revert back to the basic file monitoring code path.
This commit is contained in:
Jehan
2025-11-07 12:09:43 +01:00
committed by Philip Withnall
parent 421fa1c9ad
commit d3a16bc03c

View File

@@ -245,9 +245,9 @@ g_win32_fs_monitor_init (GWin32FSMonitorPrivate *monitor,
const gchar *filename,
gboolean isfile)
{
wchar_t *wdirname_with_long_prefix = NULL;
gchar *dirname_with_long_prefix;
wchar_t *wdirname_with_long_prefix;
const gchar LONGPFX[] = "\\\\?\\";
gchar *fullpath_with_long_prefix, *dirname_with_long_prefix;
DWORD notify_filter = isfile ?
(FILE_NOTIFY_CHANGE_FILE_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES |
@@ -260,20 +260,33 @@ g_win32_fs_monitor_init (GWin32FSMonitorPrivate *monitor,
gboolean success_attribs;
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {0, };
g_return_if_fail ((filename && isfile) || (dirname && ! isfile));
if (dirname != NULL)
{
dirname_with_long_prefix = g_strconcat (LONGPFX, dirname, NULL);
}
else
{
gchar *tmp_dirname = g_path_get_dirname (filename);
dirname_with_long_prefix = g_strconcat (LONGPFX, tmp_dirname, NULL);
g_free (tmp_dirname);
}
wdirname_with_long_prefix = g_utf8_to_utf16 (dirname_with_long_prefix, -1, NULL, NULL, NULL);
if (isfile)
{
gchar *fullpath;
gchar *fullpath_with_long_prefix;
wchar_t wlongname[MAX_PATH_LONG];
wchar_t wshortname[MAX_PATH_LONG];
wchar_t *wfullpath, *wbasename_long, *wbasename_short;
if (dirname)
fullpath = g_build_filename (dirname, filename, NULL);
else
fullpath = g_strdup (filename);
fullpath_with_long_prefix = g_strconcat (LONGPFX, fullpath, NULL);
wfullpath = g_utf8_to_utf16 (fullpath, -1, NULL, NULL, NULL);
@@ -318,6 +331,7 @@ g_win32_fs_monitor_init (GWin32FSMonitorPrivate *monitor,
g_free (wfullpath);
g_free (fullpath);
g_free (fullpath_with_long_prefix);
}
else
{
@@ -327,15 +341,6 @@ g_win32_fs_monitor_init (GWin32FSMonitorPrivate *monitor,
}
monitor->isfile = isfile;
}
else
{
dirname_with_long_prefix = g_strconcat (LONGPFX, filename, NULL);
monitor->wfullpath_with_long_prefix = g_utf8_to_utf16 (dirname_with_long_prefix, -1, NULL, NULL, NULL);
monitor->wfilename_long = NULL;
monitor->wfilename_short = NULL;
monitor->isfile = FALSE;
}
success_attribs = GetFileAttributesExW (monitor->wfullpath_with_long_prefix,
GetFileExInfoStandard,
@@ -345,7 +350,7 @@ g_win32_fs_monitor_init (GWin32FSMonitorPrivate *monitor,
else
monitor->file_attribs = INVALID_FILE_ATTRIBUTES;
monitor->pfni_prev = NULL;
monitor->hDirectory = CreateFileW (wdirname_with_long_prefix != NULL ? wdirname_with_long_prefix : monitor->wfullpath_with_long_prefix,
monitor->hDirectory = CreateFileW (wdirname_with_long_prefix,
FILE_LIST_DIRECTORY,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,