From bf417fc0347467092dfd12a72ed8177524b473d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Fri, 21 Aug 2009 11:12:43 +0200 Subject: Speed up plugin loading by not constructing a new QSettings each time. This should benefit the platforms with slow QSettings, esp. Linux. Task-number: 243398 Reviewed-by: brad --- src/corelib/plugin/qlibrary.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index ea8882f..f784622 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -416,7 +416,23 @@ static bool qt_unix_query(const QString &library, uint *version, bool *debug, QB #endif // Q_OS_UNIX && !Q_OS_MAC && !defined(QT_NO_PLUGIN_CHECK) typedef QMap LibraryMap; -Q_GLOBAL_STATIC(LibraryMap, libraryMap) + +struct LibraryData { + LibraryData() : settings(0) { } + ~LibraryData() { + delete settings; + } + + QSettings *settings; + LibraryMap libraryMap; +}; + +Q_GLOBAL_STATIC(LibraryData, libraryData) + +static LibraryMap *libraryMap() +{ + return &(libraryData()->libraryMap); +} QLibraryPrivate::QLibraryPrivate(const QString &canonicalFileName, const QString &version) :pHnd(0), fileName(canonicalFileName), fullVersion(version), instance(0), qt_version(0), @@ -597,10 +613,12 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) .arg(fileName); QStringList reg; #ifndef QT_NO_SETTINGS - bool madeSettings = false; if (!settings) { - settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech")); - madeSettings = true; + settings = libraryData()->settings; + if (!settings) { + settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech")); + libraryData()->settings = settings; + } } reg = settings->value(regkey).toStringList(); #endif @@ -679,10 +697,6 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) settings->setValue(regkey, queried); #endif } -#ifndef QT_NO_SETTINGS - if (madeSettings) - delete settings; -#endif if (!success) { if (errorString.isEmpty()){ -- cgit v0.12 From 1216161584b730576c24fb128131838be1826b37 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 21 Aug 2009 15:26:53 +0200 Subject: NTFS symlink support for QFileInfo::isSymLink() We will handle reparse points with IO_REPARSE_TAG_MOUNT_POINT and IO_REPARSE_TAG_SYMLINK tag values only. isSymlink() assumes doStat() was called early. Merge-request: 1217 Reviewed-by: Joerg Bornemann --- src/corelib/io/qfsfileengine.cpp | 2 +- src/corelib/io/qfsfileengine_p.h | 3 ++- src/corelib/io/qfsfileengine_win.cpp | 40 +++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 3d109d1..1ca19cf 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -109,7 +109,7 @@ void QFSFileEnginePrivate::init() { is_sequential = 0; tried_stat = 0; -#ifdef Q_OS_UNIX +#if !defined(Q_OS_WINCE) need_lstat = 1; is_link = 0; #endif diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 15cbf5c..3c1e7e0 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -137,10 +137,11 @@ public: mutable uint is_sequential : 2; mutable uint could_stat : 1; mutable uint tried_stat : 1; -#ifdef Q_OS_UNIX +#if !defined(Q_OS_WINCE) mutable uint need_lstat : 1; mutable uint is_link : 1; #endif + bool doStat() const; bool isSymlink() const; diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index e524e8e..7b08767 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1440,6 +1440,41 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const } /*! + \internal +*/ +bool QFSFileEnginePrivate::isSymlink() const +{ +#if !defined(Q_OS_WINCE) + if (need_lstat) { + need_lstat = false; + is_link = false; + + if (fileAttrib & FILE_ATTRIBUTE_REPARSE_POINT) { + QString path = QDir::toNativeSeparators(filePath); + // path for the FindFirstFile should not end with a trailing slash + while (path.endsWith(QLatin1Char('\\'))) + path.chop(1); + + WIN32_FIND_DATA findData; + HANDLE hFind = ::FindFirstFile((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16(), + &findData); + if (hFind != INVALID_HANDLE_VALUE) { + ::FindClose(hFind); + if ((findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + && (findData.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT + || findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) { + is_link = true; + } + } + } + } + return is_link; +#else + return false; +#endif // Q_OS_WINCE +} + +/*! \reimp */ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const @@ -1449,6 +1484,9 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil // Force a stat, so that we're guaranteed to get up-to-date results if (type & Refresh) { d->tried_stat = 0; +#if !defined(Q_OS_WINCE) + d->need_lstat = 1; +#endif } if (type & PermsMask) { @@ -1472,7 +1510,7 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil ret |= FileType; } } else if (d->doStat()) { - if (d->fileAttrib & FILE_ATTRIBUTE_REPARSE_POINT) + if ((type & LinkType) && d->isSymlink()) ret |= LinkType; if (d->fileAttrib & FILE_ATTRIBUTE_DIRECTORY) { ret |= DirectoryType; -- cgit v0.12 From 132811cd923e23832663795ddd3c67d394ffdcfb Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 21 Aug 2009 15:26:55 +0200 Subject: NTFS symlink support in QFileInfo::symLinkTarget() readSymLink() assumes isSymlink() was returned true since it expects IO_REPARSE_TAG_MOUNT_POINT and IO_REPARSE_TAG_SYMLINK tag values only. Merge-request: 1217 Reviewed-by: Joerg Bornemann --- src/corelib/io/qfsfileengine_p.h | 1 - src/corelib/io/qfsfileengine_win.cpp | 85 ++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 3c1e7e0..b245dca 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -162,7 +162,6 @@ protected: #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) QAbstractFileEngine::FileFlags getPermissions() const; - QString getLink() const; #endif }; diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 7b08767..0a5c90e 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -55,6 +55,7 @@ #if !defined(Q_OS_WINCE) # include # include +# include #else # include #endif @@ -88,6 +89,37 @@ typedef INT_PTR intptr_t; # define INVALID_FILE_ATTRIBUTES (DWORD (-1)) #endif +#if !defined(REPARSE_DATA_BUFFER_HEADER_SIZE) && !defined(Q_OS_WINCE) +typedef struct _REPARSE_DATA_BUFFER { + ULONG ReparseTag; + USHORT ReparseDataLength; + USHORT Reserved; + union { + struct { + USHORT SubstituteNameOffset; + USHORT SubstituteNameLength; + USHORT PrintNameOffset; + USHORT PrintNameLength; + ULONG Flags; + WCHAR PathBuffer[1]; + } SymbolicLinkReparseBuffer; + struct { + USHORT SubstituteNameOffset; + USHORT SubstituteNameLength; + USHORT PrintNameOffset; + USHORT PrintNameLength; + WCHAR PathBuffer[1]; + } MountPointReparseBuffer; + struct { + UCHAR DataBuffer[1]; + } GenericReparseBuffer; + }; +} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; + +# define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer) +# define MAXIMUM_REPARSE_DATA_BUFFER_SIZE 16384 +#endif + QT_BEGIN_NAMESPACE static QString readLink(const QString &link); @@ -1210,6 +1242,44 @@ bool QFSFileEnginePrivate::doStat() const } +static QString readSymLink(const QString &link) +{ + QString result; +#if !defined(Q_OS_WINCE) + HANDLE handle = CreateFile((wchar_t*)QFSFileEnginePrivate::longFileName(link).utf16(), + FILE_READ_EA, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + 0, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, + 0); + if (handle != INVALID_HANDLE_VALUE) { + DWORD bufsize = MAXIMUM_REPARSE_DATA_BUFFER_SIZE; + REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER*)qMalloc(bufsize); + DWORD retsize = 0; + if (::DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, 0, 0, rdb, bufsize, &retsize, 0)) { + if (rdb->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { + int length = rdb->MountPointReparseBuffer.SubstituteNameLength / sizeof(wchar_t); + int offset = rdb->MountPointReparseBuffer.SubstituteNameOffset / sizeof(wchar_t); + const wchar_t* PathBuffer = &rdb->MountPointReparseBuffer.PathBuffer[offset]; + result = QString::fromWCharArray(PathBuffer, length); + } else { + int length = rdb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t); + int offset = rdb->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t); + const wchar_t* PathBuffer = &rdb->SymbolicLinkReparseBuffer.PathBuffer[offset]; + result = QString::fromWCharArray(PathBuffer, length); + } + // cut-off "//?/" and "/??/" + if (result.size() > 4 && result.at(0) == QLatin1Char('\\') && result.at(2) == QLatin1Char('?') && result.at(3) == QLatin1Char('\\')) + result = result.mid(4); + } + qFree(rdb); + CloseHandle(handle); + } +#endif // Q_OS_WINCE + return result; +} + static QString readLink(const QString &link) { #if !defined(Q_OS_WINCE) @@ -1267,14 +1337,6 @@ static QString readLink(const QString &link) #endif // Q_OS_WINCE } -/*! - \internal -*/ -QString QFSFileEnginePrivate::getLink() const -{ - return readLink(filePath); -} - bool QFSFileEngine::link(const QString &newName) { #if !defined(Q_OS_WINCE) @@ -1621,7 +1683,12 @@ QString QFSFileEngine::fileName(FileName file) const } return ret; } else if(file == LinkName) { - return QDir::fromNativeSeparators(d->getLink()); + QString ret; + if (d->filePath.endsWith(QLatin1String(".lnk"))) + ret = readLink(d->filePath); + else if (d->doStat() && d->isSymlink()) + ret = readSymLink(d->filePath); + return QDir::fromNativeSeparators(ret); } else if(file == BundleName) { return QString(); } -- cgit v0.12 From c24d7ff4c933f40326c2c0b50c46ad2b59d88625 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 21 Aug 2009 15:26:58 +0200 Subject: autotests for NTFS symlink support on Windows "Default User" and "Documents and Settings" are mountpoints; "All Users" is a symlink If these subtests are successful, then we support both. Merge-request: 1217 Reviewed-by: Joerg Bornemann --- tests/auto/qfileinfo/tst_qfileinfo.cpp | 61 +++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 6c94ebf..e9d0d9d 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -139,6 +139,7 @@ private slots: void fileTimes(); void fileTimes_oldFile(); + void isSymLink_data(); void isSymLink(); void isHidden_data(); @@ -166,6 +167,10 @@ private slots: void notEqualOperator() const; }; +tst_QFileInfo::tst_QFileInfo() +{ +} + tst_QFileInfo::~tst_QFileInfo() { QFile::remove("brokenlink.lnk"); @@ -233,12 +238,6 @@ void tst_QFileInfo::copy() QVERIFY(privateInfo->data != privateInfo3->data); QVERIFY(privateInfo2->data != privateInfo3->data); QCOMPARE(privateInfo->data, privateInfo2->data); - - -} - -tst_QFileInfo::tst_QFileInfo() -{ } void tst_QFileInfo::isFile_data() @@ -514,7 +513,6 @@ void tst_QFileInfo::canonicalFilePath() } } #endif - } void tst_QFileInfo::fileName_data() @@ -714,7 +712,6 @@ void tst_QFileInfo::permission_data() QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true; QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false; QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ExeUser) << false; - } void tst_QFileInfo::permission() @@ -778,8 +775,8 @@ void tst_QFileInfo::compare_data() #else << false; #endif - } + void tst_QFileInfo::compare() { QFETCH(QString, file1); @@ -946,28 +943,46 @@ void tst_QFileInfo::fileTimes_oldFile() #endif } -void tst_QFileInfo::isSymLink() +void tst_QFileInfo::isSymLink_data() { QFile::remove("link.lnk"); QFile::remove("brokenlink.lnk"); - QFileInfo info1("tst_qfileinfo.cpp"); - QVERIFY( !info1.isSymLink() ); + QFile file1("tst_qfileinfo.cpp"); + QVERIFY(file1.link("link.lnk")); - QFile file2("tst_qfileinfo.cpp"); - if (file2.link("link.lnk")) { - QFileInfo info2("link.lnk"); - QVERIFY( info2.isSymLink() ); - } + QFile file2("dummyfile"); + file2.open(QIODevice::WriteOnly); + QVERIFY(file2.link("brokenlink.lnk")); + file2.remove(); - QFile file3("dummyfile"); - file3.open(QIODevice::WriteOnly); - if (file3.link("brokenlink.lnk")) { - file3.remove(); - QFileInfo info3("brokenlink.lnk"); - QVERIFY( info3.isSymLink() ); + + QTest::addColumn("path"); + QTest::addColumn("isSymLink"); + QTest::addColumn("linkTarget"); + + QTest::newRow("existent file") << "tst_qfileinfo.cpp" << false << ""; + QTest::newRow("link") << "link.lnk" << true << QFileInfo("tst_qfileinfo.cpp").absoluteFilePath(); + QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); + +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) { + QTest::newRow("Documents and Settings") << "C:/Documents and Settings" << true << "C:/Users"; + QTest::newRow("All Users") << "C:/Users/All Users" << true << "C:/ProgramData"; + QTest::newRow("Default User") << "C:/Users/Default User" << true << "C:/Users/Default"; } +#endif +} + +void tst_QFileInfo::isSymLink() +{ + QFETCH(QString, path); + QFETCH(bool, isSymLink); + QFETCH(QString, linkTarget); + QFileInfo fi(path); + QCOMPARE(fi.isSymLink(), isSymLink); + QCOMPARE(fi.symLinkTarget(), linkTarget); } void tst_QFileInfo::isHidden_data() -- cgit v0.12 From 634318a21b011812aea46082e2ecce0e4a5599ab Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 21 Aug 2009 15:27:00 +0200 Subject: QFSFileEngine: micro-optimization - save QString copy constructors - make QFSFileEngine::tempPath more robust on Windows Merge-request: 1217 Reviewed-by: Joerg Bornemann --- src/corelib/io/qfsfileengine_unix.cpp | 6 +++--- src/corelib/io/qfsfileengine_win.cpp | 33 ++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 96ea96e..2ebf691 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -514,21 +514,21 @@ QString QFSFileEngine::homePath() QString QFSFileEngine::rootPath() { - return QString::fromLatin1("/"); + return QLatin1String("/"); } QString QFSFileEngine::tempPath() { QString temp = QFile::decodeName(qgetenv("TMPDIR")); if (temp.isEmpty()) - temp = QString::fromLatin1("/tmp/"); + temp = QLatin1String("/tmp/"); return temp; } QFileInfoList QFSFileEngine::drives() { QFileInfoList ret; - ret.append(rootPath()); + ret.append(QFileInfo(rootPath())); return ret; } diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 0a5c90e..bac0569 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1061,7 +1061,7 @@ QString QFSFileEngine::homePath() ret = QString::fromLocal8Bit(qgetenv("HOME").constData()); if(ret.isEmpty() || !QFile::exists(ret)) { #if defined(Q_OS_WINCE) - ret = QString::fromLatin1("\\My Documents"); + ret = QLatin1String("\\My Documents"); if (!QFile::exists(ret)) #endif ret = rootPath(); @@ -1075,7 +1075,7 @@ QString QFSFileEngine::homePath() QString QFSFileEngine::rootPath() { #if defined(Q_OS_WINCE) - QString ret = QString::fromLatin1("/"); + QString ret = QLatin1String("/"); #elif defined(Q_FS_FAT) QString ret = QString::fromLatin1(qgetenv("SystemDrive").constData()); if(ret.isEmpty()) @@ -1091,20 +1091,23 @@ QString QFSFileEngine::rootPath() QString QFSFileEngine::tempPath() { - wchar_t tempPath[MAX_PATH]; - int success = GetTempPath(MAX_PATH, tempPath); - QString ret = QString::fromWCharArray(tempPath); - - if (ret.isEmpty() || !success) { + QString ret; + { + wchar_t tempPath[MAX_PATH]; + if (GetTempPath(MAX_PATH, tempPath)) + ret = QString::fromWCharArray(tempPath); + if (!ret.isEmpty()) { + while (ret.endsWith(QLatin1Char('\\'))) + ret.chop(1); + ret = QDir::fromNativeSeparators(ret); + } + } + if (ret.isEmpty()) { #if !defined(Q_OS_WINCE) - ret = QString::fromLatin1("c:/tmp"); + ret = QLatin1String("c:/tmp"); #else - ret = QString::fromLatin1("\\Temp"); + ret = QLatin1String("/Temp"); #endif - } else { - ret = QDir::fromNativeSeparators(ret); - while (ret.at(ret.length()-1) == QLatin1Char('/')) - ret = ret.left(ret.length()-1); } return ret; } @@ -1125,13 +1128,13 @@ QFileInfoList QFSFileEngine::drives() while(driveBits) { if(driveBits & 1) - ret.append(QString::fromLatin1(driveName)); + ret.append(QFileInfo(QLatin1String(driveName))); driveName[0]++; driveBits = driveBits >> 1; } return ret; #else - ret.append(QString::fromLatin1("/")); + ret.append(QFileInfo(QLatin1String("/"))); return ret; #endif } -- cgit v0.12 From 3513c1a01b319fb5fd4057be306c9f9506f8223d Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 21 Aug 2009 15:27:02 +0200 Subject: QFSFileEngine coding style fixes * removed extra whitespaces * added whitespaces between operators and brackets no code changes Merge-request: 1217 Reviewed-by: Joerg Bornemann --- src/corelib/io/qfsfileengine_unix.cpp | 10 ++--- src/corelib/io/qfsfileengine_win.cpp | 78 ++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 2ebf691..2ca0ec9 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -652,11 +652,11 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const else if (exists && (d->st.st_mode & S_IFMT) == S_IFDIR) ret |= DirectoryType; #if !defined(QWS) && defined(Q_OS_MAC) - if((ret & DirectoryType) && (type & BundleType)) { + if ((ret & DirectoryType) && (type & BundleType)) { QCFType url = CFURLCreateWithFileSystemPath(0, QCFString(d->filePath), kCFURLPOSIXPathStyle, true); UInt32 type, creator; - if(CFBundleGetPackageInfoInDirectory(url, &type, &creator)) + if (CFBundleGetPackageInfoInDirectory(url, &type, &creator)) ret |= BundleType; } #endif @@ -690,9 +690,9 @@ QString QFSFileEngine::fileName(FileName file) const #if !defined(QWS) && defined(Q_OS_MAC) QCFType url = CFURLCreateWithFileSystemPath(0, QCFString(d->filePath), kCFURLPOSIXPathStyle, true); - if(CFDictionaryRef dict = CFBundleCopyInfoDictionaryForURL(url)) { - if(CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) { - if(CFGetTypeID(name) == CFStringGetTypeID()) + if (CFDictionaryRef dict = CFBundleCopyInfoDictionaryForURL(url)) { + if (CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) { + if (CFGetTypeID(name) == CFStringGetTypeID()) return QCFString::toQString((CFStringRef)name); } } diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index bac0569..4b52ded 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -154,7 +154,7 @@ QT_END_INCLUDE_NAMESPACE void QFSFileEnginePrivate::resolveLibs() { static bool triedResolve = false; - if(!triedResolve) { + if (!triedResolve) { // need to resolve the security info functions // protect initialization @@ -162,7 +162,7 @@ void QFSFileEnginePrivate::resolveLibs() QMutexLocker locker(QMutexPool::globalInstanceGet(&triedResolve)); // check triedResolve again, since another thread may have already // done the initialization - if(triedResolve) { + if (triedResolve) { // another thread did initialize the security function pointers, // so we shouldn't do it again. return; @@ -251,7 +251,7 @@ bool QFSFileEnginePrivate::uncListSharesOnServer(const QString &server, QStringL if (resolveUNCLibs()) { SHARE_INFO_1 *BufPtr, *p; DWORD res; - DWORD er=0,tr=0,resume=0, i; + DWORD er = 0, tr = 0, resume = 0, i; do { res = ptrNetShareEnum((wchar_t*)server.utf16(), 1, (LPBYTE *)&BufPtr, DWORD(-1), &er, &tr, &resume); if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA) { @@ -263,7 +263,7 @@ bool QFSFileEnginePrivate::uncListSharesOnServer(const QString &server, QStringL } } ptrNetApiBufferFree(BufPtr); - } while (res==ERROR_MORE_DATA); + } while (res == ERROR_MORE_DATA); return res == ERROR_SUCCESS; } return false; @@ -925,7 +925,7 @@ bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) con for (int slash=0; slash != -1; oldslash = slash) { slash = dirName.indexOf(QDir::separator(), oldslash+1); if (slash == -1) { - if(oldslash == dirName.length()) + if (oldslash == dirName.length()) break; slash = dirName.length(); } @@ -980,8 +980,8 @@ bool QFSFileEngine::setCurrentPath(const QString &path) #if !defined(Q_OS_WINCE) return ::SetCurrentDirectory((wchar_t*)path.utf16()) != 0; #else - qfsPrivateCurrentDir = QFSFileEnginePrivate::longFileName(path); - return true; + qfsPrivateCurrentDir = QFSFileEnginePrivate::longFileName(path); + return true; #endif } @@ -1019,9 +1019,9 @@ QString QFSFileEngine::currentPath(const QString &fileName) ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters. return QDir::fromNativeSeparators(ret); #else - Q_UNUSED(fileName); - if (qfsPrivateCurrentDir.isEmpty()) - qfsPrivateCurrentDir = QCoreApplication::applicationDirPath(); + Q_UNUSED(fileName); + if (qfsPrivateCurrentDir.isEmpty()) + qfsPrivateCurrentDir = QCoreApplication::applicationDirPath(); return QDir::fromNativeSeparators(qfsPrivateCurrentDir); #endif @@ -1053,13 +1053,13 @@ QString QFSFileEngine::homePath() } } #endif - if(ret.isEmpty() || !QFile::exists(ret)) { + if (ret.isEmpty() || !QFile::exists(ret)) { ret = QString::fromLocal8Bit(qgetenv("USERPROFILE").constData()); - if(ret.isEmpty() || !QFile::exists(ret)) { + if (ret.isEmpty() || !QFile::exists(ret)) { ret = QString::fromLocal8Bit(qgetenv("HOMEDRIVE").constData()) + QString::fromLocal8Bit(qgetenv("HOMEPATH").constData()); - if(ret.isEmpty() || !QFile::exists(ret)) { + if (ret.isEmpty() || !QFile::exists(ret)) { ret = QString::fromLocal8Bit(qgetenv("HOME").constData()); - if(ret.isEmpty() || !QFile::exists(ret)) { + if (ret.isEmpty() || !QFile::exists(ret)) { #if defined(Q_OS_WINCE) ret = QLatin1String("\\My Documents"); if (!QFile::exists(ret)) @@ -1078,9 +1078,9 @@ QString QFSFileEngine::rootPath() QString ret = QLatin1String("/"); #elif defined(Q_FS_FAT) QString ret = QString::fromLatin1(qgetenv("SystemDrive").constData()); - if(ret.isEmpty()) + if (ret.isEmpty()) ret = QLatin1String("c:"); - ret += QLatin1Char('/'); + ret.append(QLatin1Char('/')); #elif defined(Q_OS_OS2EMX) char dir[4]; _abspath(dir, QLatin1String("/"), _MAX_PATH); @@ -1120,14 +1120,14 @@ QFileInfoList QFSFileEngine::drives() quint32 driveBits = (quint32) GetLogicalDrives() & 0x3ffffff; #elif defined(Q_OS_OS2EMX) quint32 driveBits, cur; - if(DosQueryCurrentDisk(&cur,&driveBits) != NO_ERROR) + if (DosQueryCurrentDisk(&cur, &driveBits) != NO_ERROR) exit(1); driveBits &= 0x3ffffff; #endif char driveName[] = "A:/"; - while(driveBits) { - if(driveBits & 1) + while (driveBits) { + if (driveBits & 1) ret.append(QFileInfo(QLatin1String(driveName))); driveName[0]++; driveBits = driveBits >> 1; @@ -1147,10 +1147,11 @@ bool QFSFileEnginePrivate::doStat() const if (filePath.isEmpty()) return could_stat; + QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath; fname = fixIfRelativeUncPath(fname); - UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); + UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); if (fd != -1) { #if !defined(Q_OS_WINCE) @@ -1239,6 +1240,7 @@ bool QFSFileEnginePrivate::doStat() const #endif } } + SetErrorMode(oldmode); } return could_stat; @@ -1306,11 +1308,11 @@ static QString readLink(const QString &link) if (SUCCEEDED(hres)) { // Get pointer to the IPersistFile interface. IPersistFile *ppf; hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf); - if(SUCCEEDED(hres)) { + if (SUCCEEDED(hres)) { hres = ppf->Load((LPOLESTR)link.utf16(), STGM_READ); //The original path of the link is retrieved. If the file/folder //was moved, the return value still have the old path. - if(SUCCEEDED(hres)) { + if (SUCCEEDED(hres)) { if (psl->GetPath(szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY) == NOERROR) ret = QString::fromWCharArray(szGotPath); } @@ -1380,8 +1382,8 @@ bool QFSFileEngine::link(const QString &newName) if (!ret) setError(QFile::RenameError, qt_error_string()); - if(neededCoInit) - CoUninitialize(); + if (neededCoInit) + CoUninitialize(); return ret; #else @@ -1603,32 +1605,32 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil QString QFSFileEngine::fileName(FileName file) const { Q_D(const QFSFileEngine); - if(file == BaseName) { + if (file == BaseName) { int slash = d->filePath.lastIndexOf(QLatin1Char('/')); - if(slash == -1) { + if (slash == -1) { int colon = d->filePath.lastIndexOf(QLatin1Char(':')); - if(colon != -1) + if (colon != -1) return d->filePath.mid(colon + 1); return d->filePath; } return d->filePath.mid(slash + 1); - } else if(file == PathName) { - if(!d->filePath.size()) + } else if (file == PathName) { + if (!d->filePath.size()) return d->filePath; int slash = d->filePath.lastIndexOf(QLatin1Char('/')); - if(slash == -1) { - if(d->filePath.length() >= 2 && d->filePath.at(1) == QLatin1Char(':')) + if (slash == -1) { + if (d->filePath.length() >= 2 && d->filePath.at(1) == QLatin1Char(':')) return d->filePath.left(2); return QString(QLatin1Char('.')); } else { - if(!slash) + if (!slash) return QString(QLatin1Char('/')); - if(slash == 2 && d->filePath.length() >= 2 && d->filePath.at(1) == QLatin1Char(':')) + if (slash == 2 && d->filePath.length() >= 2 && d->filePath.at(1) == QLatin1Char(':')) slash++; return d->filePath.left(slash); } - } else if(file == AbsoluteName || file == AbsolutePathName) { + } else if (file == AbsoluteName || file == AbsolutePathName) { QString ret; if (!isRelativePath()) { @@ -1642,7 +1644,7 @@ QString QFSFileEngine::fileName(FileName file) const ret = d->filePath; } #else - ret = d->filePath; + ret = d->filePath; #endif } else { ret = QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + d->filePath); @@ -1671,7 +1673,7 @@ QString QFSFileEngine::fileName(FileName file) const return ret.left(slash > 0 ? slash : 1); } return ret; - } else if(file == CanonicalName || file == CanonicalPathName) { + } else if (file == CanonicalName || file == CanonicalPathName) { if (!(fileFlags(ExistsFlag) & ExistsFlag)) return QString(); @@ -1685,14 +1687,14 @@ QString QFSFileEngine::fileName(FileName file) const ret = ret.left(slash); } return ret; - } else if(file == LinkName) { + } else if (file == LinkName) { QString ret; if (d->filePath.endsWith(QLatin1String(".lnk"))) ret = readLink(d->filePath); else if (d->doStat() && d->isSymlink()) ret = readSymLink(d->filePath); return QDir::fromNativeSeparators(ret); - } else if(file == BundleName) { + } else if (file == BundleName) { return QString(); } return d->filePath; -- cgit v0.12