Re: File saving -- how is it done?
Re: File saving -- how is it done?
- Subject: Re: File saving -- how is it done?
- From: Dominic Giampaolo <email@hidden>
- Date: Thu, 26 Apr 2007 14:32:19 -0700
... I think a lot of software just does the obvious thing: write to
a file with a temporary name, delete the old file, rename the new
file.
I sure hope that *NO ONE* does it that way.
If you create the file with a temp name and then
delete the old file the user can lose their data
if your app (or the system) were to crash before
the rename happened.
You should create the temp file and then either
use rename() or FSExchangeObjects(). The rename()
will atomically rename the temp file to the old
file name and take care of deleting the old file.
FSExchangeObjects() swaps the data forks of the
two files (and then you need to delete the temp
file which now has the old data).
You should never delete a user's data file as
part of a file save operation.
--dominic
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden