FROM : Clark Cox
DATE : Fri Dec 24 01:52:48 2004
On Thu, 23 Dec 2004 15:38:32 -0800, Chuck Soper <<email_removed>> wrote:
> Hello,
>
> I'm using this NSData's method:
> - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
> to write some data to a file on disk. It works great.
>
> If a file with the same name already exists, writeToFile: just
> replaces it. Is this expected behavior? Is this approach okay? Do you
> think that it could break in the future?
This appears to be the intended behavior. Otherwise, the "atomically:"
parameter would be pointless.
>
> Should I see if the file exists and delete if it does with these
> FileManager methods?
> - (BOOL)fileExistsAtPath:(NSString *)path
> - (BOOL)removeFileAtPath:(NSString *)path handler:(id)handler
This would prevent your write from being atomic (what happens if the
remove succeeds, but some error happens during the write; you've then
got a potentially partially written file).
--
Clark S. Cox III
<email_removed>
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
DATE : Fri Dec 24 01:52:48 2004
On Thu, 23 Dec 2004 15:38:32 -0800, Chuck Soper <<email_removed>> wrote:
> Hello,
>
> I'm using this NSData's method:
> - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
> to write some data to a file on disk. It works great.
>
> If a file with the same name already exists, writeToFile: just
> replaces it. Is this expected behavior? Is this approach okay? Do you
> think that it could break in the future?
This appears to be the intended behavior. Otherwise, the "atomically:"
parameter would be pointless.
>
> Should I see if the file exists and delete if it does with these
> FileManager methods?
> - (BOOL)fileExistsAtPath:(NSString *)path
> - (BOOL)removeFileAtPath:(NSString *)path handler:(id)handler
This would prevent your write from being atomic (what happens if the
remove succeeds, but some error happens during the write; you've then
got a potentially partially written file).
--
Clark S. Cox III
<email_removed>
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
| Related mails | Author | Date |
|---|---|---|
| Chuck Soper | Dec 24, 00:38 | |
| Clark Cox | Dec 24, 01:52 |






Cocoa mail archive

