diff options
author | Thomas Zander <t.zander@nokia.com> | 2010-08-27 08:34:01 (GMT) |
---|---|---|
committer | Thomas Zander <t.zander@nokia.com> | 2010-08-27 09:01:25 (GMT) |
commit | 710258ee0ab068bb713edc8d952293cf810a206d (patch) | |
tree | ee216f16febb98ac6c5124f265c0960038fb3dac | |
parent | 9367d50311640c1765a05b744de2ac796311fac7 (diff) | |
download | Qt-710258ee0ab068bb713edc8d952293cf810a206d.zip Qt-710258ee0ab068bb713edc8d952293cf810a206d.tar.gz Qt-710258ee0ab068bb713edc8d952293cf810a206d.tar.bz2 |
Move absoluteName to new fileSystemEngine for unix
Move the code for determining the absolute path on unix from the
qfsfileengine_unix.cpp to the new qfilesystemengine_unix.cpp which
is a static, stateless class.
Made sure that the old qfsfileengine_unix.cpp keeps on working by
calling into the new one.
Reviewed-by: João Abecasis
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 30 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 19 |
2 files changed, 34 insertions, 15 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index ac71f0e..bcd75fc 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qfilesystemengine_p.h" +#include "qfsfileengine.h" bool QFileSystemEngine::isCaseSensitive() { @@ -61,7 +62,34 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry) //static QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) { - return entry; // TODO implement; + if (entry.isAbsolute()) + return entry; + + QByteArray orig = entry.nativeFilePath(); + QByteArray result; + if (orig.isEmpty() || !orig.startsWith('/')) { + QFileSystemEntry cur(QFSFileEngine::currentPath()); + result = cur.nativeFilePath(); + } + if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) { + if (!result.isEmpty() && !result.endsWith('/')) + result.append('/'); + result.append(orig); + } + + if (result.length() == 1 && result[0] == '/') + return QFileSystemEntry(result); + const bool isDir = result.endsWith('/'); + + /* as long as QDir::cleanPath() operates on a QString we have to convert to a string here. + * ideally we never convert to a string since that loses information. Please fix after + * we get a QByteArray version of QDir::cleanPath() + */ + QFileSystemEntry resultingEntry(result); + QString stringVersion = QDir::cleanPath(resultingEntry.filePath()); + if (isDir) + stringVersion.append(QLatin1Char('/')); + return QFileSystemEntry(stringVersion); } //static diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 774932a..5fecb5d 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -43,6 +43,8 @@ #include "qabstractfileengine.h" #include "private/qfsfileengine_p.h" #include "private/qcore_unix_p.h" +#include "qfilesystementry_p.h" +#include "qfilesystemengine_p.h" #ifndef QT_NO_FSFILEENGINE @@ -1046,20 +1048,9 @@ QString QFSFileEngine::fileName(FileName file) const return QLatin1String("/"); return d->filePath.left(slash); } else if (file == AbsoluteName || file == AbsolutePathName) { - QString ret; - if (d->filePath.isEmpty() || !d->filePath.startsWith(QLatin1Char('/'))) - ret = QDir::currentPath(); - if (!d->filePath.isEmpty() && d->filePath != QLatin1String(".")) { - if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) - ret += QLatin1Char('/'); - ret += d->filePath; - } - if (ret == QLatin1String("/")) - return ret; - bool isDir = ret.endsWith(QLatin1Char('/')); - ret = QDir::cleanPath(ret); - if (isDir) - ret += QLatin1Char('/'); + QFileSystemEntry entry(d->filePath); + entry = QFileSystemEngine::absoluteName(entry); + QString ret = entry.filePath(); if (file == AbsolutePathName) { int slash = ret.lastIndexOf(QLatin1Char('/')); if (slash == -1) |