[Development] QFile: writing via a temporary file

Thiago Macieira thiago.macieira at intel.com
Fri Jan 6 22:04:56 CET 2012


On Friday, 6 de January de 2012 17.22.18, Artur Souza (MoRpHeUz) wrote:
> > If the app crashes at any other point, i.e. after close(), and then the
> > 'target' file is the one you want to open anyway.
> > 
> > The saving happens into the temp file. So there is nothing "to restore" in
> > case of a crash, that's the whole point of not touching the existing file
> > until the final atomic renaming.
> > 
> > So in fact I think you're confused about where the writing happens
> 
> Got it  Thanks for the clarification!

Another important thing is that, even without crashing, the target file is 
never found in an in-between state. It's either the old state or the new one.

Anyone reading from the file will not see modifications done on-the-fly.

Moreover, filesystems on Linux (at least) are tuned so that, if the renaming is 
recorded, the data was too. There was an issue with early ext4 that those were 
not synchronised: the writing of the rename happened up to 30 seconds before 
the writing of the file's data. That meant a crash in that rather large window 
of time would leave the file empty upon reboot.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120106/009a1e99/attachment.sig>


More information about the Development mailing list