N
Nate Smith
what about using copy first?
and what about exclusive access?
outline:
---------------------------------------------------------
actually first, grab the oldFile exclusively
if successful
then
open oldFile for Read
open saveFile for Write
copy oldFile to saveFile
close oldFile
close saveFile
if copy was successful
then
open oldFile for Write
open saveFile for Read
do the cloudy processing thing that rewrites oldFile
from the saveFile stuff & the "new stuff", whatever
the new stuff is (the changes, updates, etc.)
close oldFile
close saveFile
in case of crash in middle, saveFile should have the recovery
or if the copy step failed, oldFile is still unchanged,
and politely notify any interested parties
now release the exclusive hold on oldFile & let the race resume
else
wait until can grab oldFile exclusively in time,
where some waiting period has been established
to quit trying, and try again a "second" later
or
in case of time out, notify interested parties and
maybe quit thread with flag (duck out of the race)
NOTE:
presumably there are already other things in place elsewhere
that preserve the "new stuff" (changes, etc.) through crashes
and what about exclusive access?
outline:
---------------------------------------------------------
actually first, grab the oldFile exclusively
if successful
then
open oldFile for Read
open saveFile for Write
copy oldFile to saveFile
close oldFile
close saveFile
if copy was successful
then
open oldFile for Write
open saveFile for Read
do the cloudy processing thing that rewrites oldFile
from the saveFile stuff & the "new stuff", whatever
the new stuff is (the changes, updates, etc.)
close oldFile
close saveFile
in case of crash in middle, saveFile should have the recovery
or if the copy step failed, oldFile is still unchanged,
and politely notify any interested parties
now release the exclusive hold on oldFile & let the race resume
else
wait until can grab oldFile exclusively in time,
where some waiting period has been established
to quit trying, and try again a "second" later
or
in case of time out, notify interested parties and
maybe quit thread with flag (duck out of the race)
NOTE:
presumably there are already other things in place elsewhere
that preserve the "new stuff" (changes, etc.) through crashes