[Interest] QFile/QDir: force move mode only?
Hello, QFile/QDir rename function copies file in the case it's not possible to just move it. Is there a way to learn in advance what type of operation will occur? Let's suppose I have 10GB file. In case of copy, I would definitely like to use my own copy function and show UI with the progress of the operation. And of course I do not want to use my copy function always if the fast move is available. ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
[Interest] QFile/QDir: force move mode only?
On 5/12/19 5:00 AM, interest-requ...@qt-project.org wrote: Hello, QFile/QDir rename function copies file in the case it's not possible to just move it. Is there a way to learn in advance what type of operation will occur? Let's suppose I have 10GB file. In case of copy, I would definitely like to use my own copy function and show UI with the progress of the operation. And of course I do not want to use my copy function always if the fast move is available. You need to use a different class. Look around line 615 here https://code.woboq.org/qt5/qtbase/src/corelib/io/qfile.cpp.html // rename to final name if (QFileSystemEngine::renameFile(tmp, QFileSystemEntry(newName), error)) { d->fileEngine->setFileName(newName); d->fileName = newName; return true; } The class can be found here: https://code.woboq.org/qt5/qtbase/src/corelib/io/qfilesystemengine_p.h.html#QFileSystemEngine That's how you can catch the rename failure then do your own thing on copy. Be sure to read the comments in the file. If you will never be "just changing case" of a file name and can control that, then only that snippet should apply to you. You might want to add a conditional compile and use part of this snippet from around line 643 for the lesser platforms. if (changingCase ? d->engine()->renameOverwrite(newName) : d->engine()->rename(newName)) { unsetError(); // engine was able to handle the new name so we just reset it d->fileEngine->setFileName(newName); d->fileName = newName; return true; } That will be a bit more involved though. -- Roland Hughes, President Logikal Solutions (630)-205-1593 (cell) http://www.theminimumyouneedtoknow.com http://www.infiniteexposure.net http://www.johnsmith-book.com ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
On 2019-05-11 21:13, Alexander Dyagilev wrote: Hello, QFile/QDir rename function copies file in the case it's not possible to just move it. Is there a way to learn in advance what type of operation will occur? Let's suppose I have 10GB file. In case of copy, I would definitely like to use my own copy function and show UI with the progress of the operation. And of course I do not want to use my copy function always if the fast move is available. Hi, unless you're changing chars in the filename to uppercase/lowercase, where I know QFile tries to help on case-insensitive filesystems, QFile/QDir is pretty much at the mercy of the OS, i.e. if the OS refuses the renaming (for example on NTFS when you try to rename across volumes) then QFile dutifully copies the file instead. So I think this is not a Qt question and you need to drop down to the OS level, for example on Windows you can call ::MoveFileEx() with the 3rd param = 0, then the call will err out if a copy is needed. (Note: I haven't tested this myself, just relying on Google :-) Rgrds Henry ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
-Original Message- From: Interest On Behalf Of Henry Skoglund Sent: Saturday, May 11, 2019 2:22 PM To: interest@qt-project.org Subject: Re: [Interest] QFile/QDir: force move mode only? On 2019-05-11 21:13, Alexander Dyagilev wrote: > Hello, > > QFile/QDir rename function copies file in the case it's not possible > to just move it. > > Is there a way to learn in advance what type of operation will occur? > > Let's suppose I have 10GB file. In case of copy, I would definitely > like to use my own copy function and show UI with the progress of the > operation. > > And of course I do not want to use my copy function always if the fast > move is available. > Hi, unless you're changing chars in the filename to uppercase/lowercase, where I know QFile tries to help on case-insensitive filesystems, QFile/QDir is pretty much at the mercy of the OS, i.e. if the OS refuses the renaming (for example on NTFS when you try to rename across volumes) then QFile dutifully copies the file instead. So I think this is not a Qt question and you need to drop down to the OS level, for example on Windows you can call ::MoveFileEx() with the 3rd param = 0, then the call will err out if a copy is needed. (Note: I haven't tested this myself, just relying on Google :-) Rgrds Henry ___ If you are "moving" across a volume, why would you ever want to block the move, simply because in reality it’s a copy? I would think it would be best, to "move" but allow the OS to do a copy if necessary. Scott ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
On 5/12/2019 12:22 AM, Henry Skoglund wrote: QFile/QDir is pretty much at the mercy of the OS, i.e. if the OS refuses the renaming (for example on NTFS when you try to rename across volumes) then QFile dutifully copies the file instead. I know it. That's is what the question about. How to avoid this behavior. So I think this is not a Qt question Definitely it's a Qt question. Qt could provide some flag to avoid this unwanted behavior. ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
And yes, this is a really unwanted behavior and it was a short-sighted decision to make it behave so. QFile::rename should rename always or fail! It should never do completely different operation - copy! On 5/13/2019 12:26 PM, Alexander Dyagilev wrote: On 5/12/2019 12:22 AM, Henry Skoglund wrote: QFile/QDir is pretty much at the mercy of the OS, i.e. if the OS refuses the renaming (for example on NTFS when you try to rename across volumes) then QFile dutifully copies the file instead. I know it. That's is what the question about. How to avoid this behavior. So I think this is not a Qt question Definitely it's a Qt question. Qt could provide some flag to avoid this unwanted behavior. ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
> QFile::rename should rename always or fail! It should never do > completely different operation - copy! I agree. -- Best Regards, Bernhard ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
On 13/05/2019 11:31, Alexander Dyagilev wrote: And yes, this is a really unwanted behavior and it was a short-sighted decision to make it behave so. QFile::rename should rename always or fail! It should never do completely different operation - copy! It doesn't solve the problem at hand directly, but: have you considered using KIO? My 2 c, -- Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts smime.p7s Description: S/MIME Cryptographic Signature ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
On 5/13/19, Bernhard Lindner wrote: >> QFile::rename should rename always or fail! It should never do >> completely different operation - copy! > > I agree. > Adding a non-copying rename method to QFile/etc seems justified. Maybe call it: fastRename, tryRename, or atomicRename? d3fault ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
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. > Sent: Monday, May 13, 2019 at 10:11 PM > From: "d3fault" > To: interest@qt-project.org > Subject: Re: [Interest] QFile/QDir: force move mode only? > > On 5/13/19, Bernhard Lindner wrote: > >> QFile::rename should rename always or fail! It should never do > >> completely different operation - copy! > > > > I agree. > > > > Adding a non-copying rename method to QFile/etc seems justified. Maybe > call it: fastRename, tryRename, or atomicRename? > > d3fault > ___ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest > ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
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. (I can't also think of an API at the OS level that could answer your question -- rename(2), link(2) etc. are all "destructive" syscalls. But maybe there is some trick.) However: KIO::rename fails if the rename cannot be performed, and you can then use move: https://api.kde.org/frameworks/kio/html/namespaceKIO.html#a399cbd217c9a897db18ea247fb289c84 Not entirely sure how to fix QFile::rename for this purpose (maybe adding a flag, making it fail if the rename requires a copy), or if it's even worth it given KIO exists. My 2 c, -- Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts smime.p7s Description: S/MIME Cryptographic Signature ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
> Sent: Tuesday, May 14, 2019 at 10:15 AM > From: "Giuseppe D'Angelo via Interest" > To: interest@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. ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] QFile/QDir: force move mode only?
https://stackoverflow.com/questions/56151795/forbid-rename-to-copy-a-file On 5/11/2019 10:13 PM, Alexander Dyagilev wrote: Hello, QFile/QDir rename function copies file in the case it's not possible to just move it. Is there a way to learn in advance what type of operation will occur? Let's suppose I have 10GB file. In case of copy, I would definitely like to use my own copy function and show UI with the progress of the operation. And of course I do not want to use my copy function always if the fast move is available. ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest