microsoft / windows-container-tools

Collection of tools to improve the Windows Containers experience
MIT License
236 stars 66 forks source link

[Fix] Bug 34: Monitor files at Windows root directory #154

Closed TinaMor closed 10 months ago

TinaMor commented 11 months ago

PR Description

This PR allows us to monitor files in the root directory e.g. C:\

Solution

For root directory, do not prepend, otherwise, prepend "\?\" to the directory path. We validate the config file to check that when the root directory is provided, includeSubdirectories must be false. Otherwise, the appliation terminates with an error.

image

TL;DR

By default, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, we prepend "\?\" to the path in LogFileMonitor.cpp. Prepending the string "\?\" does not allow access to the root directory. Maximum Path Length Limitation In editions of Windows before Windows 10 version 1607, the maximum length for a path is MAX_PATH, which is defined as 260 characters. In later versions of Windows, changing a registry key or using the Group Policy tool is required to remove the limit. See Maximum Path Length Limitation for full details. There is no limit on the depth of a file or directory. With the standard API you can create as many folders as you want until the actual length of the expanded path exceeds 32,767 characters. The math on that is 2¹⁵ minus 1. The limitation of 32,767 doesn’t come from NTFS. It comes from the Win32 API.

References

  1. FindFirstFileW function (fileapi.h)
  2. Naming Files, Paths, and Namespaces
  3. Maximum Path Length Limitation
bobsira commented 11 months ago

The looks good to me. I've noticed a few issues while try to test your code.

  1. If I begin monitoring the C: without having a log file and create the logfile later on I keep getting LogFilesChangeHandler: Timer event even after the log file is created and I'm pushing data to that log file.
  2. If I begin monitoring the C: with a log file already there I still see the LogFilesChangeHandler: Timer event

Is this the expected behavior and I'm not sure if it is related to this PR as well?

logfilemon

TinaMor commented 10 months ago

@bobsira I accidentally uncommeted out code

The looks good to me. I've noticed a few issues while try to test your code.

  1. If I begin monitoring the C: without having a log file and create the logfile later on I keep getting LogFilesChangeHandler: Timer event even after the log file is created and I'm pushing data to that log file.
  2. If I begin monitoring the C: with a log file already there I still see the LogFilesChangeHandler: Timer event

Is this the expected behavior and I'm not sure if it is related to this PR as well?

logfilemon