moveToTrash/Unix: remove unnecessary targetPath variable

It was used twice, in both cases to create a QFileSystemEntry, so the
two results were equal. Therefore, just use the first result to create
the second.

Change-Id: I9d43e5b91eb142d6945cfffd1786d45d20485f40
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 3d027f8d959879d0c0525fedd03907a607ea32ee)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2023-09-20 22:56:46 -07:00 committed by Qt Cherry-pick Bot
parent 81b6eb264d
commit 2fb2b238de

View File

@ -1361,9 +1361,6 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
uniqueTrashedName = makeUniqueTrashedName(); uniqueTrashedName = makeUniqueTrashedName();
} while (!infoFile.isOpen()); } while (!infoFile.isOpen());
const QString targetPath = trashDir.filePath(filesDir) + uniqueTrashedName;
const QFileSystemEntry target(targetPath);
QString pathForInfo; QString pathForInfo;
const QStorageInfo storageInfo(sourcePath); const QStorageInfo storageInfo(sourcePath);
if (storageInfo.isValid() && storageInfo.rootPath() != rootPath() && storageInfo != QStorageInfo(QDir::home())) { if (storageInfo.isValid() && storageInfo.rootPath() != rootPath() && storageInfo != QStorageInfo(QDir::home())) {
@ -1379,6 +1376,7 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
In that case, we don't try further, i.e. copying and removing the original 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. is usually not what the user would expect to happen.
*/ */
QFileSystemEntry target(trashDir.filePath(filesDir) + uniqueTrashedName);
if (!renameFile(source, target, error)) { if (!renameFile(source, target, error)) {
infoFile.close(); infoFile.close();
infoFile.remove(); infoFile.remove();
@ -1393,7 +1391,7 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
infoFile.write(info); infoFile.write(info);
infoFile.close(); infoFile.close();
newLocation = QFileSystemEntry(targetPath); newLocation = std::move(target);
return true; return true;
#endif // QT_BOOTSTRAPPED #endif // QT_BOOTSTRAPPED
} }