realbasic-nug
[Top] [All Lists]

Re: Should I Delete to Overwrite?

To: REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Should I Delete to Overwrite?
From: Additional Mac List Distribution <maclists at additional dot com>
Date: Fri, 30 Aug 2002 15:44:45 -0400
On Friday, August 30, 2002, at 02:53  PM, Joseph J. Strout wrote:

At 2:45 PM -0400 8/30/02, Charles Yeomans wrote:

It would be safer to write the new file to a temporary file, then swap the contents of the two files. There are MacOS File Manager functions that you can use to do this. I assume that the Windows API supports this sort of operation as well.

Though not quite as good as swapping the file contents, there's another method that's almost and good but more portable. Write out your new file to the same folder but with a temporary file name (just make up one that doesn't already exist). Then, when that's done successfully, rename the old file to a different temporary name, name your new file to its proper name, and delete the old file.

In any case, the idea is to put off deleting the old file as long as possible, so that if you crash (lose power, etc.) in the middle of saving, the user's data isn't lost.

Sure, but it's much more macho to use a toolbox call.

Charles Yeomans

The toolbox call also has the advantage that you don't lose meta-data (original creation date, finder comments, custom icons, label, other things).

If you use the 2nd method above (swapping names) don't forget to copy the metadata too. (Used to be GetFInfo() call I think, but you can do some of it in RB.)

It involves twice as much data be written, but you could copy the old file into a temp file (.BAK), close it, zero the length of the original file & write your data into it, close it, then delete the temp copy. Whew! Guess that's why there's a system call!

Dave

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:realbasic-nug-off at lists dot realsoftware dot com>

Subscribe to the digest: <mailto:realbasic-nug-digest at lists dot realsoftware dot com>
.


<Prev in Thread] Current Thread [Next in Thread>