fix NTFS mount points

NTFS mount points are not treated as symlinks, because they might
not have a link target.
This is the case when a volume is mounted as a single mount point
without a drive letter.
This patch fixes building Qt in an NTFS mount point.

Task-number: QTBUG-20431
Change-Id: Ie2e15212e1a7ca7fa0067b7ca8857e243e42c21a
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Joerg Bornemann 2012-01-17 14:21:05 +01:00 committed by Qt by Nokia
parent b41fd5cf12
commit 1656c4780c
4 changed files with 25 additions and 12 deletions

View File

@ -792,9 +792,10 @@ static bool tryFindFallback(const QFileSystemEntry &fname, QFileSystemMetaData &
int errorCode = GetLastError(); int errorCode = GetLastError();
if (errorCode == ERROR_ACCESS_DENIED || errorCode == ERROR_SHARING_VIOLATION) { if (errorCode == ERROR_ACCESS_DENIED || errorCode == ERROR_SHARING_VIOLATION) {
WIN32_FIND_DATA findData; WIN32_FIND_DATA findData;
if (getFindData(fname.nativeFilePath(), findData) const QString nativeFilePath = fname.nativeFilePath();
if (getFindData(nativeFilePath, findData)
&& findData.dwFileAttributes != INVALID_FILE_ATTRIBUTES) { && findData.dwFileAttributes != INVALID_FILE_ATTRIBUTES) {
data.fillFromFindData(findData, true, fname.isDriveRoot()); data.fillFromFindData(findData, true, fname.isDriveRoot(), nativeFilePath);
filledData = true; filledData = true;
} }
} }
@ -875,8 +876,9 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
data.knownFlagsMask |= QFileSystemMetaData::LinkType; data.knownFlagsMask |= QFileSystemMetaData::LinkType;
if (data.fileAttribute_ & FILE_ATTRIBUTE_REPARSE_POINT) { if (data.fileAttribute_ & FILE_ATTRIBUTE_REPARSE_POINT) {
WIN32_FIND_DATA findData; WIN32_FIND_DATA findData;
if (getFindData(fname.nativeFilePath(), findData)) const QString nativeFilePath = fname.nativeFilePath();
data.fillFromFindData(findData, true); if (getFindData(nativeFilePath, findData))
data.fillFromFindData(findData, true, false, nativeFilePath);
} }
} }
data.knownFlagsMask |= what; data.knownFlagsMask |= what;

View File

@ -138,7 +138,7 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa
fileEntry = QFileSystemEntry(dirPath + fileName); fileEntry = QFileSystemEntry(dirPath + fileName);
metaData = QFileSystemMetaData(); metaData = QFileSystemMetaData();
if (!fileName.endsWith(QLatin1String(".lnk"))) { if (!fileName.endsWith(QLatin1String(".lnk"))) {
metaData.fillFromFindData(findData, true); metaData.fillFromFindData(findData, true, false, fileEntry.nativeFilePath());
} }
return true; return true;
} }

View File

@ -234,7 +234,7 @@ public:
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
inline void fillFromFileAttribute(DWORD fileAttribute, bool isDriveRoot = false); inline void fillFromFileAttribute(DWORD fileAttribute, bool isDriveRoot = false);
inline void fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType = false, bool isDriveRoot = false); inline void fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType = false, bool isDriveRoot = false, const QString &nativeFullFilePath = QString());
inline void fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo); inline void fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo);
#endif #endif
private: private:
@ -350,7 +350,7 @@ inline void QFileSystemMetaData::fillFromFileAttribute(DWORD fileAttribute,bool
knownFlagsMask |= FileType | DirectoryType | HiddenAttribute | ExistsAttribute; knownFlagsMask |= FileType | DirectoryType | HiddenAttribute | ExistsAttribute;
} }
inline void QFileSystemMetaData::fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType, bool isDriveRoot) inline void QFileSystemMetaData::fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType, bool isDriveRoot, const QString &nativeFullFilePath)
{ {
fillFromFileAttribute(findData.dwFileAttributes, isDriveRoot); fillFromFileAttribute(findData.dwFileAttributes, isDriveRoot);
creationTime_ = findData.ftCreationTime; creationTime_ = findData.ftCreationTime;
@ -368,12 +368,23 @@ inline void QFileSystemMetaData::fillFromFindData(WIN32_FIND_DATA &findData, boo
knownFlagsMask |= LinkType; knownFlagsMask |= LinkType;
entryFlags &= ~LinkType; entryFlags &= ~LinkType;
#if !defined(Q_OS_WINCE) #if !defined(Q_OS_WINCE)
if ((fileAttribute_ & FILE_ATTRIBUTE_REPARSE_POINT) if (fileAttribute_ & FILE_ATTRIBUTE_REPARSE_POINT) {
&& (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) { if (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
entryFlags |= LinkType; entryFlags |= LinkType;
} else if (findData.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT) {
// Junctions and mount points are implemented as NTFS reparse points.
// But mount points cannot be treated as symlinks because they might
// not have a link target.
wchar_t buf[50];
QString path = nativeFullFilePath;
if (!path.endsWith(QLatin1Char('\\')))
path.append(QLatin1Char('\\'));
BOOL isMountPoint = GetVolumeNameForVolumeMountPoint(reinterpret_cast<const wchar_t*>(path.utf16()), buf, sizeof(buf) / sizeof(wchar_t));
if (!isMountPoint)
entryFlags |= LinkType;
}
} }
#endif #endif
} }
} }

View File

@ -1390,7 +1390,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
junction = "mountpoint"; junction = "mountpoint";
rootVolume.replace("\\\\?\\","\\??\\"); rootVolume.replace("\\\\?\\","\\??\\");
FileSystem::createNtfsJunction(rootVolume, junction); FileSystem::createNtfsJunction(rootVolume, junction);
QTest::newRow("mountpoint") << junction << true << QDir::fromNativeSeparators(rootPath) << QDir::rootPath(); QTest::newRow("mountpoint") << junction << false << QString() << QFileInfo(junction).canonicalFilePath();
} }
} }