Re: How can I do a 100% bullet proof 'Save'?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Norm Dresner (ndrez_at_att.net)
Date: 09/24/04


Date: Fri, 24 Sep 2004 20:46:25 GMT


"Simon" <sorde@gotadsl.co.uk> wrote in message
news:4153e126$0$52238$65c69314@mercury.nildram.net...
> Norm (& others)
> The advantage of your approach over mine is therefore that 2 things have
to
> go wrong in the same operation for the bad result (wrongly named original
> file) to occur. And as there is no reason to expect that these failures
> would be in any way related to one another, that would be exceptionally
bad
> luck.
>
> However, the disadvantage of your approach is that there is slightly more
to
> go wrong. On my approach, the bad result can only arise if the final
rename
> fails (which is exactly what happened). On your approach, if either the
> delete file fails, or the final rename, the bad result will arise.
>

(Norm:) With my approach:
                        1. Rename old file
                        2. Write new file
                        3. Delete old file

If the delete fails, you still have a good new file written to the disk.
The only bad side-effect is having the extra file there. And I have no
final rename -- you write the new file with the correct name in the first
place.
    There's still a cascade of failures possible if the write fails and then
the renaming of the old file back to the original name fails too, you're
left with a situation in which the file has the wrong name -- but it's still
there.
    This method is pretty much safe against power failures too as long as
you can detect if the "new" file is bad.

I'm not sure that there is a completely foolproof method -- anything's going
to be susceptible to corruption if the power fails at exactly the wrong
time. Pretty much the only way to guard against that is to copy the
original file to removable media which the user takes out of the computer
before anything else is done.

Don't shoot for 100% safe; settle for 99.9% -- it's much easier on your
mental health.

    Norm



Relevant Pages

  • Re: IE 7 Update
    ... Windows Shell/User ... "Norm S" wrote: ... | I am trying to install IE 7 through Windows Update. ... It fails every time. ...
    (microsoft.public.windowsupdate)
  • How can I do a 100% bullet proof Save?
    ... I delete the old file and rename my saved file to give ... If anything fails at any point, I leave the old file alone and tell the user ... the saved file (with the temp name) to use the old name, ...
    (microsoft.public.vc.mfc)
  • Re: How can I do a 100% bullet proof Save?
    ... Try ReplaceFile API. ... >i.e. if the save fails for any reason, the file on disk is left completely ... > attempt to rename the saved file to use the old name, ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH] failslab - failmalloc for slab allocator
    ... specifies how often it should fail in percent. ... specifies how many times failures may happen at most. ... slab allocation fails once per 10 times. ...
    (Linux-Kernel)
  • Re: ActiveState module failures
    ... Here's a selection of suspicious reports from the 5.8 A section. ... causes a cascade of failures. ... Practically everything in Apache:: fails due to some missing prerequisite. ...
    (comp.lang.perl.modules)