QFileInfo: Fail faster when stat'ing filepath on a disconnected drive

The Windows implementation of QFileSystemEngine tries hard to fill the
metadata for a file, even if GetFileAttributesEx returns with error.
This is good in many situations, but when the error code indicates that
the drive on which the file resides has been disconnected, then we
should fail quickly.

Task-number: QTBUG-6039
Pick-to: 5.15
Change-Id: I7574c5a2e524e913306d0b470b4f227416442c13
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-07-28 11:20:24 +02:00
parent 8969070cfd
commit d14cf6d3d9

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -1062,8 +1062,10 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
if (ok) { if (ok) {
data.fillFromFindData(findData, false, fname.isDriveRoot()); data.fillFromFindData(findData, false, fname.isDriveRoot());
} else { } else {
if (!tryFindFallback(fname, data)) const DWORD lastError = GetLastError();
if (!tryDriveUNCFallback(fname, data)) { if (lastError == ERROR_LOGON_FAILURE || lastError == ERROR_BAD_NETPATH // disconnected drive
|| (!tryFindFallback(fname, data) && !tryDriveUNCFallback(fname, data))) {
data.clearFlags();
SetErrorMode(oldmode); SetErrorMode(oldmode);
return false; return false;
} }