I've got a configuration folder in the root of the user directory. For example, ~/.ztool
and there is a file named status
in this folder which can be created, updated or deleted and it is important to know the status of this file. Existing command-line tools use and modify this status
file. I've created code which monitors the folder and file but I think the Sandbox security on the Mac is causing the DispatchSource to miss key events. For entitlements I have had to add the following to the entitlements file.
<key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key>
<array>
<string>/.ztool</string>
<string>/.ztool/status</string>
</array>
My understanding is that if I use DispatchSource
for the makeFileSystemObjectSource
function to monitor the folder it should handle events related to any changes to files in this folder. It appears that is not happening. I can instead directly monitor the file for changes, but if it is deleted that monitor will not work. I have found that if the file does not exist and the DispatchSource
is monitoring the folder that it does handle an event when the file is created. What I'd like to know is if there is a way to configure the entitlements to allow for using DispatchSource
to monitor file changes in the folder. Or will it be necessary to monitor the folder until the file is created and then change the DispatchSource
to monitor the file?
What I may have to do is start and cancel 2 monitors if I cannot just use the directory monitor. I've shared the code as a Gist on GitHub. It is linked below.