summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine_unix.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-01-31 12:54:17 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-02-04 11:58:56 +0100
commit336b3bb0dd494409b89e1de480eb7204ff7b554e (patch)
treed9e16d5eeaab4dcb701ada5bcc165940fbccdb39 /src/corelib/io/qfilesystemengine_unix.cpp
parent6b858e21ed1ac3c665ab5cd608078dfe00283f8f (diff)
Address failing test case for internal implementation of moveToTrash
This ammends 601ce9e08aa92b273f1a6daf0bdbc67dbf9b4e5f, which added a new test case for the internal Qt APIs. The test was not getting executed by coin as it wasn't included in the io.pro file, and trying to fix that generates link errors on Windows, since these internal APIs depend on other internal APIs. Short of bootstrapping much of QtCore into this test case, the only sensible option is to remove this test case again, and cover the testing when the public API is added in a follow up commit. At the same time, address those failures that were discovered on platforms that could build the test, and fix compilation on iOS platforms in Coin. Change-Id: Id31b43c9df9f205476c48bccb6b87c7a53ed15c5 Reviewed-by: Vitaly Fanaskov <vitaly.fanaskov@qt.io>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 16901be187..eed34086b4 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -1341,13 +1341,15 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
QString infoFileName;
int counter = 0;
QFile infoFile;
- do {
- while (QFile::exists(trashDir.filePath(filesDir) + uniqueTrashedName)) {
- ++counter;
- uniqueTrashedName = QString(QLatin1String("/%1-%2"))
+ auto makeUniqueTrashedName = [trashedName, &counter]() -> QString {
+ ++counter;
+ return QString(QLatin1String("/%1-%2"))
.arg(trashedName)
.arg(counter, 4, 10, QLatin1Char('0'));
- }
+ };
+ do {
+ while (QFile::exists(trashDir.filePath(filesDir) + uniqueTrashedName))
+ uniqueTrashedName = makeUniqueTrashedName();
/*
"The $trash/info directory contains an "information file" for every file and directory
in $trash/files. This file MUST have exactly the same name as the file or directory in
@@ -1363,15 +1365,21 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
infoFileName = trashDir.filePath(infoDir)
+ uniqueTrashedName + QLatin1String(".trashinfo");
infoFile.setFileName(infoFileName);
- } while (!infoFile.open(QIODevice::NewOnly | QIODevice::WriteOnly | QIODevice::Text));
+ if (!infoFile.open(QIODevice::NewOnly | QIODevice::WriteOnly | QIODevice::Text))
+ uniqueTrashedName = makeUniqueTrashedName();
+ } while (!infoFile.isOpen());
const QString targetPath = trashDir.filePath(filesDir) + uniqueTrashedName;
const QFileSystemEntry target(targetPath);
+ /*
+ We might fail to rename if source and target are on different file systems.
+ In that case, we don't try further, i.e. copying and removing the original
+ is usually not what the user would expect to happen.
+ */
if (!renameFile(source, target, error)) {
infoFile.close();
infoFile.remove();
- error = QSystemError(errno, QSystemError::StandardLibraryError);
return false;
}