[Development] QFile: writing via a temporary file

Oswald Buddenhagen oswald.buddenhagen at nokia.com
Fri Jan 6 11:48:34 CET 2012


On Fri, Jan 06, 2012 at 09:59:10AM +0100, ext Eirik Aavitsland wrote:
> On 01/06/2012 12:45 AM, ext Craig.Scott at csiro.au wrote:
> > The temporary file is meant to be an updated version of the real
> > target. If you want to call rename(), you really should first commit
> > any changes and then rename the file. Similarly, if you want to call
> > remove(), you are either removing the original/target or you are
> > wanting to discard your changes in which case a separate function for
> > doing that (as proposed) seems better. Thus, I don't think rename()
> > or remove() should nor need to work on the temporary file.
> >
rename() implicitly closes first, so by definition this would commit and
rename the original file.
remove() should simply error out, because there is no intuitive answer
to the question which of the files to delete. that's why i think it is
ok to overload its meaning with rollback() - nobody would expect
something different anyway.

> You may also consider whether, instead of adding a separate API for 
> enabling this functionality (e.g. file.setUseTemporaryFile(bool)), one 
> could simply add another QIODevice::OpenModeFlag. Say, 
> QIODevice::Indirect or something. Because the feature is somewhat akin 
> to QIODevice::Unbuffered, ::Append and ::Truncate.
> 
i was thinking the same.
Indirect is a bit broad. UseTemporary or SafeWrite would be closer to
being intuitive, even if they look less elegant.

On Thu, Jan 05, 2012 at 10:38:37PM -0200, ext Thiago Macieira wrote:                                                                                               
> What happens if you open the file in read or read-write mode while the
> flag is on?
>
for read-only this is obviously meaningless.
the mode is inherently incompatible with read-write without truncate.
in read-write with truncate mode, read operations should simply refer to
the temporary file. this is consistent with what you would get otherwise
(you start with an empty file anyway).



More information about the Development mailing list