Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Checking file modification dates in NSDocument



Hello,

Before my users save files they've opened I want to first detect if any other users (on the network or otherwise) have modified the file. I want to do this by checking the mod date on the file before the user saves, and then compare this date to the mod date when the file was opened.

  My application is NSDocument based.

  Currently am doing the following:

1. Caching the mod date when the file is opened in awakeFromNib in MyDocument. 2. I compare the current mod date to the cached copy at the top of NSDocument's writeToFile.
3. Then at the end of writeToFile I'm re-caching the date.


  If this were working, I wouldn't be writing.  ;-)

  I'm writing the file data with [NSData writeToFile:path atomically:YES].

There's lots of exchanging going on. Cocoa appears to be threading/delaying the file writes somehow. And the modification dates I'm getting back are never correct. (Because of the caching.)

I'm currently grabbing the modification dates with stat(2). I'm getting my file path with [[document_ fileName] fileSystemRepresentation].

Where are the best places to hook into NSDocument to get accurate modification dates on files for caching and comparison?

Thanks,
  Sanford

PS - I've read TN2037 and don't want to implement file locking.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.