I've been trying to use FileMonitor to track down a really annoying and elusive bug with 0-byte files (files getting spuriously emptied and losing their data). I'm trying to trigger this bug while FileMonitor is running, and I'm seeing some weird behavior where it seems as if iCloud's daemons (bird and whatever other daemons run in the background and handle iCloud file sync) are able to modify the filesystem right under the nose of tools like FileMonitor.
Here's a POC script for testing - requires jq (brew install jq)
poor-mans-fsusage.sh
#!/usr/bin/env bash
logfile="$HOME/Desktop/FileMonitor.log"
re="^$HOME/Library/Mobile Documents/com~apple~CloudDocs/xyzzy.txt"
e_types='["ES_EVENT_TYPE_NOTIFY_CLONE","ES_EVENT_TYPE_NOTIFY_CREATE","ES_EVENT_TYPE_NOTIFY_FCNTL","ES_EVENT_TYPE_NOTIFY_RENAME","ES_EVENT_TYPE_NOTIFY_SETACL","ES_EVENT_TYPE_NOTIFY_SETATTRLIST","ES_EVENT_TYPE_NOTIFY_SETEXTATTR","ES_EVENT_TYPE_NOTIFY_SETFLAGS","ES_EVENT_TYPE_NOTIFY_SETMODE","ES_EVENT_TYPE_NOTIFY_SETOWNER","ES_EVENT_TYPE_NOTIFY_SETTIME","ES_EVENT_TYPE_NOTIFY_TRUNCATE","ES_EVENT_TYPE_NOTIFY_UNLINK","ES_EVENT_TYPE_NOTIFY_WRITE"]'echo"% logging started (file: $logfile)"| tee -a "$logfile"echo"% using regex: $re"| tee -a "$logfile"
sudo /Applications/FileMonitor.app/Contents/MacOS/FileMonitor -pretty |
jq --raw-output --unbuffered --argjson e "$e_types" --arg re "$re"' select(.event? | IN($e[])) | select(.file.destination?|match($re)) | [ .event, .file.process.name, .file.destination ] | @tsv'|
tee -a "$logfile"
Running this script and then creating/updating the xyzzy.txt file at the root of iCloud Drive with common tools like Sublime Text, echo foo >>xyzzy.txt or rm xyzzy.txt produces output like this:
However, if I open this file up on my iPhone (using Files.app) and modify it there, a strange thing happens. No ES_EVENT_TYPE_NOTIFY_WRITE events are seen. Yet the file somehow gets updated. It appears that maybe there is some sort of atomic saving going on (temp file saving, moving (renaming) the original, replacing etc. But I can't be sure. Here's a sample of the output:
So it looks like a bunch of other helpers are involved in a simple file update on iCloud. I see nsurlsessiond, cloudd, nehelper... is there any sane way to log this type of activity?
The text was updated successfully, but these errors were encountered:
I've been trying to use FileMonitor to track down a really annoying and elusive bug with 0-byte files (files getting spuriously emptied and losing their data). I'm trying to trigger this bug while FileMonitor is running, and I'm seeing some weird behavior where it seems as if iCloud's daemons (
birdand whatever other daemons run in the background and handle iCloud file sync) are able to modify the filesystem right under the nose of tools like FileMonitor.Here's a POC script for testing - requires jq (
brew install jq)poor-mans-fsusage.sh
Running this script and then creating/updating the
xyzzy.txtfile at the root of iCloud Drive with common tools like Sublime Text,echo foo >>xyzzy.txtorrm xyzzy.txtproduces output like this:However, if I open this file up on my iPhone (using Files.app) and modify it there, a strange thing happens. No
ES_EVENT_TYPE_NOTIFY_WRITEevents are seen. Yet the file somehow gets updated. It appears that maybe there is some sort of atomic saving going on (temp file saving, moving (renaming) the original, replacing etc. But I can't be sure. Here's a sample of the output:If I change the filtering to log all
NOTIFY_WRITEs, I get a flurry of activity (I de-duped all the log lines below otherwise it would be pages long)output:
So it looks like a bunch of other helpers are involved in a simple file update on iCloud. I see
nsurlsessiond,cloudd,nehelper... is there any sane way to log this type of activity?The text was updated successfully, but these errors were encountered: