File corruption with KSaveFile on full disk

David Faure faure at kde.org
Fri Feb 6 19:13:55 GMT 2009


On Tuesday 20 January 2009, Thiago Macieira wrote:
> Em Terça-feira 20 Janeiro 2009, às 00:40:43, David Faure escreveu:
> > On Sunday 18 January 2009, Thiago Macieira wrote:
> > > Michael Leupold wrote:
> > > >I seem to have to check the return value and use waitForBytesWritten()
> > > > unless I'm using unbuffered output as QIODevice::write() might (will?)
> > > > return the number of bytes I tried to write even if the disk is full.
> > > > That's at least what a simple test suggests.
> > >
> > > Use an unbuffered QFile and check the return value of write().
> >
> > Wow, we do the latter already in saving-code (KZip, KOffice, ...),
> > but we don't use Unbuffered mode... It worked in qt3/kde3 without
> > unbuffered, I'm sure.
> 
> The problem with buffered mode is that write() will report that it wrote all 
> bytes, but the saving of them to disk might fail. In that case, the write 
> happens inside flush() 

So a solution is to test the return value of flush(), right? That's actually easier
than checking each and every write() call... (and much more performant
than using Unbuffered).

When does flush happen if not called explicitely? In close? So we should do this?

--- kio/karchive.cpp    (revision 917300)
+++ kio/karchive.cpp    (working copy)
@@ -176,8 +176,12 @@ KArchive::close()
             d->abortWriting();
     }

-    if ( d->dev )
+    if ( d->dev ) {
+        if (!d->dev->flush()) {
+            return false;
+        }
         d->dev->close();
+    }

     if ( d->deviceOwned ) {
         delete d->dev; // we created it ourselves in open()


-- 
David Faure, faure at kde.org, sponsored by Qt Software @ Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list