I've been using FileWatcher to perform actions on new/changed files. I ran into problems where FileWatcher invokes the block before the file has finished copying and my code then fails.
My script runs using launchd so I considered investigating the WatchPaths
launchd.plist directive. The man page for that directive says not to use it because of the some of the problems I've been having with FileWatcher.
Use of this key is highly discouraged, as filesystem event monitoring is highly race-prone, and it is entirely possible for modifications to be missed. When modifications are caught, there is no guarantee that the file will be in a consistent state when the job is launched.
The scripts in this gist are investigations into alternative approaches to only acting on files that have been created/changed.
In 'storing-a-hash-of-files.rb' I also compared the performance of Ruby's Digest::MD5
to the system md5
but there didn't seem to be any difference. The system md5
required me to use Shellwords
to escape the filenames so ultimately I think the Digest::MD5
version is a bit easier to understand.