summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp23
-rw-r--r--tests/auto/qfileinfo/tst_qfileinfo.cpp14
2 files changed, 29 insertions, 8 deletions
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 50b4af7..80ccda3 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -865,15 +865,22 @@ QString QFSFileEngine::fileName(FileName file) const
QString ret;
if (!isRelativePathSymbian(d->filePath)) {
if (d->filePath.size() > 2 && d->filePath.at(1) == QLatin1Char(':')
- && d->filePath.at(2) != slashChar || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt
- d->filePath.startsWith(slashChar) // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt
- ) {
- ret = QString(QDir::currentPath().left(2) + QDir::fromNativeSeparators(d->filePath));
+ && d->filePath.at(2) != slashChar){
+ // It's a drive-relative path, so C:a.txt -> C:/currentpath/a.txt,
+ // or if it's different drive than current, Z:a.txt -> Z:/a.txt
+ QString currentPath = QDir::currentPath();
+ if (0 == currentPath.left(1).compare(d->filePath.left(1), Qt::CaseInsensitive))
+ ret = currentPath + slashChar + d->filePath.mid(2);
+ else
+ ret = d->filePath.left(2) + slashChar + d->filePath.mid(2);
+ } else if (d->filePath.startsWith(slashChar)) {
+ // It's a absolute path to the current drive, so /a.txt -> C:/a.txt
+ ret = QDir::currentPath().left(2) + d->filePath;
} else {
ret = d->filePath;
}
} else {
- ret = QDir::cleanPath(QDir::currentPath() + slashChar + d->filePath);
+ ret = QDir::currentPath() + slashChar + d->filePath;
}
// The path should be absolute at this point.
@@ -889,6 +896,12 @@ QString QFSFileEngine::fileName(FileName file) const
ret[0] = ret.at(0).toUpper();
}
+ // Clean up the path
+ bool isDir = ret.endsWith(slashChar);
+ ret = QDir::cleanPath(ret);
+ if (isDir)
+ ret += slashChar;
+
if (file == AbsolutePathName) {
int slash = ret.lastIndexOf(slashChar);
if (slash < 0)
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp
index d951a86..076934c 100644
--- a/tests/auto/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp
@@ -411,6 +411,10 @@ void tst_QFileInfo::absolutePath_data()
QString drivePrefix;
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
drivePrefix = QDir::currentPath().left(2);
+
+ // Make sure drive-relative paths return correct absolute paths (task 255326)
+ QTest::newRow("c:my.dll") << "c:my.dll" << QDir::currentPath() << "my.dll";
+ QTest::newRow("x:my.dll") << "x:my.dll" << "X:/" << "my.dll";
#endif
QTest::newRow("0") << "/machine/share/dir1/" << drivePrefix + "/machine/share/dir1" << "";
QTest::newRow("1") << "/machine/share/dir1" << drivePrefix + "/machine/share" << "dir1";
@@ -449,6 +453,10 @@ void tst_QFileInfo::absFilePath_data()
curr.remove(0, 2); // Make it a absolute path with no drive specifier: \depot\qt-4.2\tests\auto\qfileinfo
QTest::newRow(".") << curr << QDir::currentPath();
QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "C:/home/andy/tmp.txt";
+
+ // Make sure drive-relative paths return correct absolute paths (task 255326)
+ QTest::newRow("c:my.dll") << "c:temp/my.dll" << QDir::currentPath() + "/temp/my.dll";
+ QTest::newRow("x:my.dll") << "x:temp/my.dll" << "X:/temp/my.dll";
#else
QTest::newRow("absFilePath") << "/home/andy/tmp.txt" << "/home/andy/tmp.txt";
#endif
@@ -1052,19 +1060,19 @@ void tst_QFileInfo::isHidden_data()
QFile file(hiddenFileName);
if (file.open(QIODevice::WriteOnly)) {
QTextStream t(&file);
- t << "foobar";
+ t << "foobar";
} else {
qWarning("Failed to create hidden file");
}
QFile file2(notHiddenFileName);
if (file2.open(QIODevice::WriteOnly)) {
QTextStream t(&file);
- t << "foobar";
+ t << "foobar";
} else {
qWarning("Failed to create non-hidden file");
}
}
-
+
RFs rfs;
TInt err = rfs.Connect();
if (err == KErrNone) {