From ce820174ee20a161570a31cdc7f945f535177efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 15 Jan 2025 14:10:41 +0100 Subject: [PATCH] QFile::rename: error out if overwrite fails when changing case on case-insensitive filesystems The generic copy-and-remove fallback will first open the original file with a different case, truncate it, and then remove the original file. Leaving us with no file at all. Task-number: QTBUG-132785 Pick-to: 6.8 6.5 Change-Id: Ia5a41d26c1d6d6bdc231c71acf15bd2ea496c715 Reviewed-by: Thiago Macieira (cherry picked from commit 2defca418788ab167fa1ce70e518c9250cb0909f) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfile.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 9295070dc8a..7e7c16c4660 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -654,6 +654,13 @@ QFile::rename(const QString &newName) return true; } + // Engine was unable to rename and the fallback will delete the original file, + // so we have to back out here on case-insensitive file systems: + if (changingCase) { + d->setError(QFile::RenameError, d->fileEngine->errorString()); + return false; + } + if (isSequential()) { d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy")); return false;