Make QFile::copy() less likely to create zero-sized
QFile::copy() didn't have the syncToDisk() call that QSaveFile::commit() has. So add it. [ChangeLog][QtCore][QFile] Made QFile::copy() issue a filesystem- synchronization system call, which would make it less likely to result in incomplete or corrupt files if the system reboots or uncleanly shuts down soon after the function returns. New code is advised to use QSaveFile instead, which also allows to display a progress report while copying. Fixes: QTBUG-75407 Change-Id: I95ecabe2f50e450c991afffd1598d09ec73f6482 Reviewed-by: Henrik Hartz <hhartz@gmail.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
parent
b4cc294347
commit
a3acf568d1
@ -832,10 +832,16 @@ QFile::copy(const QString &newName)
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (!error && !out.rename(newName)) {
|
||||
error = true;
|
||||
close();
|
||||
d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName));
|
||||
|
||||
if (!error) {
|
||||
// Sync to disk if possible. Ignore errors (e.g. not supported).
|
||||
d->fileEngine->syncToDisk();
|
||||
|
||||
if (!out.rename(newName)) {
|
||||
error = true;
|
||||
close();
|
||||
d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName));
|
||||
}
|
||||
}
|
||||
#ifdef QT_NO_TEMPORARYFILE
|
||||
if (error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user