title: File monitor stop after save file
body: <p>I'm trying to monitor the edition of a single file using <code>kqueue</code> through a wrapper called UKKQueue available <a href="https://github.com/uliwitness/UliKit" rel="nofollow">here</a>. This wrapper is very simple, here is the test code I'm using:</p>
  
  <pre><code>@implementation FileMonitorTestAppDelegate
  
  @synthesize window;
  
  - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  {
      fileWatcher = [[UKKQueue alloc] init];
      [fileWatcher addPath:@"/Users/bruno/Desktop/SyncTestLog"];
      [fileWatcher setDelegate:self];
  }
  
  - (void)dealloc {
      [fileWatcher release];
  }
  
  -(void) watcher: (id&lt;UKFileWatcher&gt;)kq receivedNotification: (NSString*)nm forPath: (NSString*)fpath {
      NSLog(@"UKFileWatcher: %@ - notification: %@ - filePath: %@", kq, nm, fpath);
  }
  
  @end
  </code></pre>
  
  <p>The file at <code>/Users/bruno/Desktop/SyncTestLog</code> is a plain text file. When I edit it using <code>nano</code> from the terminal the output shows as expected:</p>
  
  <pre><code>2011-08-17 11:46:27.316 FileMonitorTest[1235:707] UKFileWatcher: &lt;UKKQueue: 0x100117da0&gt; - notification: UKKQueueFileWrittenToNotification - filePath: /Users/bruno/Desktop/SyncTestLog
  2011-08-17 11:46:27.317 FileMonitorTest[1235:707] UKFileWatcher: &lt;UKKQueue: 0x100117da0&gt; - notification: UKKQueueFileSizeIncreasedNotification - filePath: /Users/bruno/Desktop/SyncTestLog
  2011-08-17 11:46:27.751 FileMonitorTest[1235:707] UKFileWatcher: &lt;UKKQueue: 0x100117da0&gt; - notification: UKKQueueFileAttributesChangedNotification - filePath: /Users/bruno/Desktop/SyncTestLog
  </code></pre>
  
  <p>Now, when I edit it using TextEdit or TextWrangler the monitoring stop reporting changes after the first time I save the file. Heres is the last events reported:</p>
  
  <pre><code>2011-08-17 10:57:45.792 FileMonitorTest[897:707] UKFileWatcher: &lt;UKKQueue: 0x10035ae10&gt; - notification: UKKQueueFileAttributesChangedNotification - filePath: /Users/bruno/Desktop/SyncTestLog
  2011-08-17 10:57:46.463 FileMonitorTest[897:707] UKFileWatcher: &lt;UKKQueue: 0x10035ae10&gt; - notification: UKKQueueFileAttributesChangedNotification - filePath: /Users/bruno/Desktop/SyncTestLog
  2011-08-17 10:57:54.043 FileMonitorTest[897:707] UKFileWatcher: &lt;UKKQueue: 0x10035ae10&gt; - notification: UKKQueueFileDeletedNotification - filePath: /Users/bruno/Desktop/SyncTestLog
  </code></pre>
  
  <p>As far as I understand the UKKQueue gets a unix-like file descriptor with <a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/open.2.html" rel="nofollow">open()</a> using the flag <code>O_EVTONLY</code>. For some reason the TextEdit (and TextWrangler) generate this <code>UKKQueueFileDeletedNotification</code> notification when save the file.</p>
  
  <p>What I need is keep listening for changes in the file "for ever". I suppose that I can re create the monitor when the <code>UKKQueueFileDeletedNotification</code> arrives but I'm looking for something more clean.</p>
  
  <p>Thanks</p>
  
  <p><em>Edit:</em>
  I'm just found the in the <a href="http://code.google.com/p/google-toolbox-for-mac/" rel="nofollow">Google Toolbox For Mac</a> a class called <a href="http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMFileSystemKQueue.h" rel="nofollow">GTMFileSystemKQueue</a> that's solve my problem. Still no answer for my question.</p>