[Qt-interest] QFile::rename safety

Jason H scorp1us at yahoo.com
Fri May 7 03:46:19 CEST 2010


It completely depends on implementation. It will use your OS's implementation, as far as I know. Assuming that is the case, it will depend on your filesystems.

If you move across file systems, this will have to be a copy and delete. If you move on the same filesystem, it will only have to rename the file in whatever bookkeeping it does. Basically, it is an atomic change to the file allocation table, or a relinking to another node in the tree. Journaling filesystems will maintain a backup for you, ext3 maintains a structure journal but not a data journal by default. It will either recover with the old name or it will be the new name.

You can usually call sync() to make sure everything is committed, but this is discouraged because it will reduce system performance. 








________________________________
From: Israel Brewster <israel at frontierflying.com>
To: Qt-interest Interest <qt-interest at trolltech.com>
Sent: Thu, May 6, 2010 3:02:28 PM
Subject: [Qt-interest] QFile::rename safety

How "safe" is QFile::rename? Is there a situation under which, if it fails, the file/directory in question could end up being deleted? I've always been taught never to move, instead to copy, verify that the copy succeeded, then delete the old one. In my particular usage case, though, I'm not actually moving the file, just changing the same, so should that be safe enough, given how rename works? Thanks.


-----------------------------------------------
Israel Brewster
Computer Support Technician II
Era Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x7293
-----------------------------------------------


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100506/60cd262a/attachment.html 


More information about the Qt-interest-old mailing list