Mailing Lists: Apple Mailing Lists

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

Re: Checking file modification dates in NSDocument



On 7/27/06, Sanford Selznick <email@hidden> wrote:

   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.

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

Be sure to understand what the 'atomically' flag does. It creates a *second* file, and moves it to where the first one was. You're not modifying the pre-existent file in place.

PS - I've read TN2037 and don't want to implement file locking.

Then you're aware that all of the other work you're doing is ultimately for nothing, due to the inherent race condition between when you check for changes and when you commit the new file? If you don't use locks, then this code will quite possibly still destroy data under heavy use. You say you don't want to use locks, but you're writing code to ultimately do the same thing -- with the difference being that locks will prevent corruption, while your code will not.

J.
_______________________________________________
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.