• 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: 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


  • Follow-Ups:
    • Re: File saving -- how is it done?
      • From: Laurence Harris <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>)

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