diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2010-10-14 13:06:20 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2010-10-20 13:35:05 (GMT) |
commit | 4bdf081da0276f55662de826568441ca0e85e877 (patch) | |
tree | b632860ecbc420d322497d029d4a3c61235ce270 | |
parent | 366d2ed09ebf5aa27171a46d723497e5aaa5dd06 (diff) | |
download | Qt-4bdf081da0276f55662de826568441ca0e85e877.zip Qt-4bdf081da0276f55662de826568441ca0e85e877.tar.gz Qt-4bdf081da0276f55662de826568441ca0e85e877.tar.bz2 |
Move QDir::fromNativeSeparators call to the QFileSystemEntry constructor
The m_filePath should always have / as the separator, while m_nativeFilePath
should always have the native separator.
Almost every place the constructor is used, the path could be one passed
into an API from code outside our control.
So it's easier to do the path conversion in the constructor than to have to
remember to call fromNativeSeparators in every place a QFileSystemEntry is
constructed (especially since unix tests won't reveal any error)
Reviewed-By: joao
-rw-r--r-- | src/corelib/io/qdir.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_symbian.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_win.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfilesystementry.cpp | 24 | ||||
-rw-r--r-- | src/corelib/io/qfilesystementry_p.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 2 |
7 files changed, 33 insertions, 9 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index e9bc012..22a3baa 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -177,7 +177,7 @@ inline void QDirPrivate::setPath(const QString &path) p.truncate(p.length() - 1); } - dirEntry = QFileSystemEntry(p); + dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath()); metaData.clear(); initFileEngine(); clearFileLists(); @@ -198,7 +198,7 @@ inline void QDirPrivate::resolveAbsoluteEntry() const if (dirEntry.isRelative()) { QFileSystemEntry answer = QFileSystemEngine::absoluteName(dirEntry); - absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(answer.filePath())); + absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(answer.filePath()), QFileSystemEntry::FromInternalPath()); } else { absoluteDirEntry = dirEntry; } @@ -1757,7 +1757,7 @@ QChar QDir::separator() */ bool QDir::setCurrent(const QString &path) { - return QFileSystemEngine::setCurrentPath(QFileSystemEntry(fromNativeSeparators(path))); + return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path)); } /*! diff --git a/src/corelib/io/qfilesystemengine_symbian.cpp b/src/corelib/io/qfilesystemengine_symbian.cpp index 89a2b29..c4e8d36 100644 --- a/src/corelib/io/qfilesystemengine_symbian.cpp +++ b/src/corelib/io/qfilesystemengine_symbian.cpp @@ -148,7 +148,7 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry) result.append(orig); } - return QFileSystemEntry(symbianCleanAbsolutePath(result)); + return QFileSystemEntry(symbianCleanAbsolutePath(result), QFileSystemEntry::FromInternalPath()); } //static diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index 53b9e43..8fa4d62 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -444,7 +444,7 @@ QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, ret = readLink(link); else if (data.isLink()) ret = readSymLink(link); - return QFileSystemEntry(QDir::fromNativeSeparators(ret)); + return QFileSystemEntry(ret); } //static diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp index bc7f121..d4c6d0a 100644 --- a/src/corelib/io/qfilesystementry.cpp +++ b/src/corelib/io/qfilesystementry.cpp @@ -81,7 +81,25 @@ QFileSystemEntry::QFileSystemEntry() { } +/*! + \internal + Use this constructor when the path is supplied by user code, as it may contain a mix + of '/' and the native separator. + */ QFileSystemEntry::QFileSystemEntry(const QString &filePath) + : m_filePath(QDir::fromNativeSeparators(filePath)), + m_lastSeparator(-2), + m_firstDotInFileName(-2), + m_lastDotInFileName(0) +{ +} + +/*! + \internal + Use this constructor when the path is guaranteed to be in internal format, i.e. all + directory separators are '/' and not the native separator. + */ +QFileSystemEntry::QFileSystemEntry(const QString &filePath, FromInternalPath /* dummy */) : m_filePath(filePath), m_lastSeparator(-2), m_firstDotInFileName(-2), @@ -89,6 +107,10 @@ QFileSystemEntry::QFileSystemEntry(const QString &filePath) { } +/*! + \internal + Use this constructor when the path comes from a native API + */ QFileSystemEntry::QFileSystemEntry(const NativePath &nativeFilePath, FromNativePath /* dummy */) : m_nativeFilePath(nativeFilePath), m_lastSeparator(-2), @@ -98,7 +120,7 @@ QFileSystemEntry::QFileSystemEntry(const NativePath &nativeFilePath, FromNativeP } QFileSystemEntry::QFileSystemEntry(const QString &filePath, const NativePath &nativeFilePath) - : m_filePath(filePath), + : m_filePath(QDir::fromNativeSeparators(filePath)), m_nativeFilePath(nativeFilePath), m_lastSeparator(-2), m_firstDotInFileName(-2), diff --git a/src/corelib/io/qfilesystementry_p.h b/src/corelib/io/qfilesystementry_p.h index 7a9c2a5..2ce0a83 100644 --- a/src/corelib/io/qfilesystementry_p.h +++ b/src/corelib/io/qfilesystementry_p.h @@ -72,10 +72,12 @@ public: typedef QString NativePath; #endif struct FromNativePath{}; + struct FromInternalPath{}; QFileSystemEntry(); explicit QFileSystemEntry(const QString &filePath); + QFileSystemEntry(const QString &filePath, FromInternalPath dummy); QFileSystemEntry(const NativePath &nativeFilePath, FromNativePath dummy); QFileSystemEntry(const QString &filePath, const NativePath &nativeFilePath); diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 9c8df39..5491caf 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -140,7 +140,7 @@ QFSFileEngine::QFSFileEngine(const QString &file) : QAbstractFileEngine(*new QFSFileEnginePrivate) { Q_D(QFSFileEngine); - d->fileEntry = QFileSystemEntry(QDir::fromNativeSeparators(file)); + d->fileEntry = QFileSystemEntry(file); } /*! @@ -189,7 +189,7 @@ void QFSFileEngine::setFileName(const QString &file) { Q_D(QFSFileEngine); d->init(); - d->fileEntry = QFileSystemEntry(QDir::fromNativeSeparators(file)); + d->fileEntry = QFileSystemEntry(file); } /*! diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 96946d6..28e0677 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -640,7 +640,7 @@ bool QFSFileEngine::caseSensitive() const bool QFSFileEngine::setCurrentPath(const QString &path) { - return QFileSystemEngine::setCurrentPath(QFileSystemEntry(QDir::fromNativeSeparators(path))); + return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path)); } QString QFSFileEngine::currentPath(const QString &) |