I have an application which I use to monitor file/dir changes within a directory. However, this directory also contains symlinks to other directories (which are accessible). However, when I modify a file within a symlink directory, the notification is not triggered. E.g. when I monitor Root:
--Root
--Dir
--File1 //Trigger works
--SDir(Symlink dir)
--File2 //Trigger won't work
However, when I monitor Root/SDir, which is the symlink directory than the trigger on File2 works correctly. E.g.:
--SDir
--File2 //Trigger works
So when the symlink directory is not the root, it won't trigger on file changes within that directory. However, when I set the symlink directory as the root, it works fine. And yes, the bWatchSubtree parameter within the ReadDirectoryChangesW-function is set to true.
For the good order, I open the directory handle using the CreateFile function:
CreateFile(
Dir, //Root or Root/SDir in this example
FILE_LIST_DIRECTORY,
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);
So, why won't the trigger work on files within symlinks if that same symlink is not the root of ReadDirectoryChangesW?
Here's one way to set up watch over an entire tree... These are excepts from my code base, I can't put the entire code here because of dependencies...
Usage:
Events are automatic reset, so there's no maintenance to do on that.
Stuff that's not there:
CIRSingleLock is like lock_guard
DirScanner is a wrapper around FindFirstFile(), it reports folders to the Reader struct.
include file:
cpp.