• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: File saving -- how is it done?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File saving -- how is it done?


  • Subject: Re: File saving -- how is it done?
  • From: Laurence Harris <email@hidden>
  • Date: Thu, 26 Apr 2007 18:11:59 -0400


On Apr 26, 2007, at 5:32 PM, Dominic Giampaolo wrote:

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

I think of it more as "misplaced." ;-)

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.

Yes, I'm sure many are using rename(), although I wouldn't bet my firstborn child that everyone is doing that. ;-) How can rename() do everything atomically?


FSExchangeObjects() swaps the data forks of the
two files (and then you need to delete the temp
file which now has the old data).

I was under the impression that it swaps the files' catalog entries, so data fork, resource fork, and all metadata should be included in the swap as well.


You should never delete a user's data file as
part of a file save operation.

Well, not until you have the new version in place.

Larry

_______________________________________________
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


References: 
 >File saving -- how is it done? (From: "Ian Archer" <email@hidden>)
 >Re: File saving -- how is it done? (From: Laurence Harris <email@hidden>)
 >Re: File saving -- how is it done? (From: Dominic Giampaolo <email@hidden>)

  • Prev by Date: Re: File saving -- how is it done?
  • Next by Date: /.vol file system
  • Previous by thread: Re: File saving -- how is it done?
  • Next by thread: /.vol file system
  • Index(es):
    • Date
    • Thread