diff options
author | Zeno Albisser <zeno.albisser@nokia.com> | 2010-05-05 14:36:02 (GMT) |
---|---|---|
committer | Zeno Albisser <zeno.albisser@nokia.com> | 2010-05-07 10:53:14 (GMT) |
commit | 8955e088aa9e4b0496c32f27206fd6211a85782f (patch) | |
tree | 99d41e95a163be5fa70acf98a2727fb14968ffa5 | |
parent | 9a46da1a9b045354e936ff0e3c5ca3d79baef655 (diff) | |
download | Qt-8955e088aa9e4b0496c32f27206fd6211a85782f.zip Qt-8955e088aa9e4b0496c32f27206fd6211a85782f.tar.gz Qt-8955e088aa9e4b0496c32f27206fd6211a85782f.tar.bz2 |
Fix for qfsfileengine_win to return proper absolute path for C:\
When using canonicalPath on a QDir that currently just represents
a root directory, a valid path name such as "C:\" should be returned.
Previously we returned "C:" which in fact would point to the current
working directory on drive C: and therefor is not necessarily the same.
Reviewed-by: Thiago
Task-number: QTBUG-6680
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qdir/tst_qdir.cpp | 41 |
2 files changed, 47 insertions, 4 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index cc9b8c7..254c03e 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1664,10 +1664,12 @@ QString QFSFileEngine::fileName(FileName file) const if (!isRelativePath()) { #if !defined(Q_OS_WINCE) - if ((d->filePath.size() > 2 && d->filePath.at(1) == QLatin1Char(':') - && d->filePath.at(2) != QLatin1Char('/')) || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt - d->filePath.startsWith(QLatin1Char('/')) // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt - ) { + if (d->filePath.startsWith(QLatin1Char('/')) || // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt + d->filePath.size() == 2 || // It's a drive letter that needs to get a working dir appended + (d->filePath.size() > 2 && d->filePath.at(2) != QLatin1Char('/')) || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt + d->filePath.contains(QLatin1String("/../")) || d->filePath.contains(QLatin1String("/./")) || + d->filePath.endsWith(QLatin1String("/..")) || d->filePath.endsWith(QLatin1String("/."))) + { ret = QDir::fromNativeSeparators(nativeAbsoluteFilePath(d->filePath)); } else { ret = d->filePath; diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp index 71469bb..b2dc960 100644 --- a/tests/auto/qdir/tst_qdir.cpp +++ b/tests/auto/qdir/tst_qdir.cpp @@ -172,6 +172,11 @@ private slots: void longFileName(); void updateFileLists(); + +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + void isRoot_data(); + void isRoot(); +#endif }; // Testing get/set functions @@ -805,6 +810,16 @@ void tst_QDir::canonicalPath_data() QTest::newRow("absPath") << appPath + "\\testData\\..\\testData" << appPath + "/testData"; #endif QTest::newRow("nonexistant") << "testd" << QString(); + +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QTest::newRow("drive:/") << QDir::rootPath() << QDir::rootPath(); + QTest::newRow("drive:\\") << QDir::toNativeSeparators(QDir::rootPath()) << QDir::rootPath(); + QTest::newRow("drive:/./") << QDir::rootPath().append("./") << QDir::rootPath(); + QTest::newRow("drive:/../.. ") << QDir::rootPath().append("../..") << QDir::rootPath(); + QTest::newRow("drive:\\.\\") << QDir::toNativeSeparators(QDir::rootPath().append("./")) << QDir::rootPath(); + QTest::newRow("drive:\\..\\..") << QDir::toNativeSeparators(QDir::rootPath().append("../..")) << QDir::rootPath(); + QTest::newRow("drive:") << QDir::rootPath().left(2) << QDir::currentPath(); +#endif } void tst_QDir::canonicalPath() @@ -1546,6 +1561,32 @@ void tst_QDir::updateFileLists() QCOMPARE(dir.entryList(), QStringList() << "sub-dir1" << "sub-dir2" << "file1.txt"); } +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) +void tst_QDir::isRoot_data() +{ + QTest::addColumn<QString>("path"); + QTest::addColumn<bool>("isRoot"); + + QString test = QDir::rootPath(); + QTest::newRow("rootPath " + test) << test << true; + test = QDir::rootPath().append("./"); + QTest::newRow("./ appended " + test) << test << false; + test = QDir(QDir::rootPath().append("./")).canonicalPath(); + QTest::newRow("canonicalPath " + test) << test << true; + test = QDir::rootPath().left(2); + QTest::newRow("drive relative " + test) << test << false; +} + +void tst_QDir::isRoot() +{ + QFETCH(QString, path); + QFETCH(bool, isRoot); + + QDir dir(path); + QCOMPARE(dir.isRoot(),isRoot); +} +#endif + QTEST_MAIN(tst_QDir) #include "tst_qdir.moc" |