[Interest] QFile/QDir: force move mode only?

Jason H jhihn at gmx.com
Tue May 14 20:22:40 CEST 2019



> Sent: Tuesday, May 14, 2019 at 10:15 AM
> From: "Giuseppe D'Angelo via Interest" <interest at qt-project.org>
> To: interest at qt-project.org
> Subject: Re: [Interest] QFile/QDir: force move mode only?
>
> Hi,
>
> On 14/05/2019 15:47, Jason H wrote:
> > I'd rather static bool QFile::isAtomicRename(const QString &source, cont QString &dest);
> > So that the software can plan accordingly. Blindly executing won't allow the software to accomodate non-atomic renames (i.e. Display an alternate UI). It would also be nice if there was an atomic-esque non-atomic rename, that would be a copy to the target FS and then atomic rename.
>
> Such a function would be inherently racy (the moment you have that
> information, the information is already outdated, as the filesystem may
> have changed). Suppose the function returns true, you then call
> QFile::rename() and may end up copying anyway.

Yes, all accesses to a shared resources beyond your control are inherently racy. Even if you logically can prove that the change will by all detectable means be possible, it doesn't mean it will actually happen. You really need to know if you can do it atomically, before attempting to do so, otherwise you have to fall back to a copy and atomic move. But to determine that you need to know what filesystems are mounted where, copy to the same fs as the destination then do the atomic rename. Can you still consider that atomic? I think you can hide a lot, but if the copy fails, the rename will necessarily fail, similarly if it all succeeds, it succeeds. At least there is an implication that atomic is fast,  but it isn't necessarily so.


More information about the Interest mailing list