diff options
author | Thomas Zander <t.zander@nokia.com> | 2010-09-01 11:33:12 (GMT) |
---|---|---|
committer | Thomas Zander <t.zander@nokia.com> | 2010-09-01 11:35:23 (GMT) |
commit | d3b152ba1e3cd38dd675c801474105d518bacb44 (patch) | |
tree | 4d05283d8aeeeb18788513612df89aebd57e9892 | |
parent | 5e1196c2c98b5331c0ccdbfa2aea26b35fb4a3c1 (diff) | |
download | Qt-d3b152ba1e3cd38dd675c801474105d518bacb44.zip Qt-d3b152ba1e3cd38dd675c801474105d518bacb44.tar.gz Qt-d3b152ba1e3cd38dd675c801474105d518bacb44.tar.bz2 |
Finish canonicalized for all platforms
QFSFileEnginePrivate::canonicalized is now removed and spread out
over the qfsfileengine_unix.cpp and qfsfileengine.cpp
Reviewed-by: João Abecasis
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 27 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_win.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 50 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_p.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 17 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 15 |
6 files changed, 35 insertions, 77 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 283c787..62fb1b3 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -45,6 +45,10 @@ #include <stdlib.h> // for realpath() #include <errno.h> +#if defined(Q_OS_MAC) +# include <private/qcore_mac_p.h> +#endif + QT_BEGIN_NAMESPACE bool QFileSystemEngine::isCaseSensitive() @@ -71,8 +75,27 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry) #ifdef __UCLIBC__ return QFileSystemEntry::slowCanonicalName(entry); #else - - char *ret = realpath(entry.nativeFilePath().constData(), (char*)0); + char *ret = 0; +# if defined(Q_OS_MAC) + // Mac OS X 10.5.x doesn't support the realpath(X,0) extension we use here. + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { + ret = realpath(entry.nativeFilePath().constData(), (char*)0); + } else { + // on 10.5 we can use FSRef to resolve the file path. + QString path = QDir::cleanPath(entry.filePath()); + FSRef fsref; + if (FSPathMakeRef((const UInt8 *)path.toUtf8().data(), &fsref, 0) == noErr) { + CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref); + CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle); + QString ret = QCFString::toQString(canonicalPath); + CFRelease(canonicalPath); + CFRelease(urlref); + return QFileSystemEntry(ret); + } + } +# else + ret = realpath(entry.nativeFilePath().constData(), (char*)0); +# endif if (ret) { QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret)); free(ret); diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index 40df120..aa6d2b1 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -57,7 +57,7 @@ QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link) //static QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry) { - return entry; // TODO implement; + return QFileSystemEntry(slowCanonicalized(entry.filePath())); } //static diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 665d23e..5d7b354 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -134,56 +134,6 @@ void QFSFileEnginePrivate::init() } /*! - \internal - - Returns the canonicalized form of \a path (i.e., with all symlinks - resolved, and all redundant path elements removed. -*/ -QString QFSFileEnginePrivate::canonicalized(const QString &path) -{ - if (path.isEmpty()) - return path; - - // FIXME let's see if this stuff works, then we might be able to remove some of the other code. -#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) - if (path.size() == 1 && path.at(0) == QLatin1Char('/')) - return path; -#endif -#if defined(Q_OS_LINUX) || defined(Q_OS_SYMBIAN) || defined(Q_OS_MAC) - // ... but Linux with uClibc does not have it -#if !defined(__UCLIBC__) - char *ret = 0; -#if defined(Q_OS_MAC) - // Mac OS X 10.5.x doesn't support the realpath(X,0) extension we use here. - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { - ret = realpath(path.toLocal8Bit().constData(), (char*)0); - } else { - // on 10.5 we can use FSRef to resolve the file path. - FSRef fsref; - if (FSPathMakeRef((const UInt8 *)QDir::cleanPath(path).toUtf8().data(), &fsref, 0) == noErr) { - CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref); - CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle); - QString ret = QCFString::toQString(canonicalPath); - CFRelease(canonicalPath); - CFRelease(urlref); - return ret; - } - } -#else - ret = realpath(path.toLocal8Bit().constData(), (char*)0); -#endif - if (ret) { - QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret)); - free(ret); - return canonicalPath; - } -#endif -#endif - - return QFileSystemEngine::slowCanonicalized(path); -} - -/*! Constructs a QFSFileEngine for the file name \a file. */ QFSFileEngine::QFSFileEngine(const QString &file) diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 74cbca3..9eaf6fd 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -75,7 +75,6 @@ public: #ifdef Q_WS_WIN static QString longFileName(const QString &path); #endif - static QString canonicalized(const QString &path); QFileSystemEntry fileEntry; QIODevice::OpenMode openMode; diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 29491f5..0b73a7b 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -963,19 +963,10 @@ QString QFSFileEngine::fileName(FileName file) const } return ret; } else if(file == CanonicalName || file == CanonicalPathName) { - if (!(fileFlags(ExistsFlag) & ExistsFlag)) - return QString(); - - QString ret = QFSFileEnginePrivate::canonicalized(fileName(AbsoluteName)); - if (file == CanonicalPathName && !ret.isEmpty()) { - int slash = ret.lastIndexOf(slashChar); - if (slash == -1) - ret = QDir::fromNativeSeparators(QDir::currentPath()); - else if (slash == 0) - ret = QLatin1String("/"); - ret = ret.left(slash); - } - return ret; + QFileSystemEntry entry(QFileSystemEngine::canonicalName(d->fileEntry)); + if (file == CanonicalPathName) + return entry.path(); + return entry.filePath(); } else if(file == LinkName) { if (d->isSymlink()) { char s[PATH_MAX+1]; diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 9f33af5..bc88776 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -43,6 +43,7 @@ #include "qplatformdefs.h" #include "qabstractfileengine.h" #include "private/qfsfileengine_p.h" +#include "qfilesystemengine_p.h" #include <qdebug.h> #include "qfile.h" @@ -1620,17 +1621,11 @@ QString QFSFileEngine::fileName(FileName file) const } else if (file == CanonicalName || file == CanonicalPathName) { if (!(fileFlags(ExistsFlag) & ExistsFlag)) return QString(); + QFileSystemEngine entry(QFileSystemEngine::slowCanonicalized(fileName(AbsoluteName))); - QString ret = QFSFileEnginePrivate::canonicalized(fileName(AbsoluteName)); - if (!ret.isEmpty() && file == CanonicalPathName) { - int slash = ret.lastIndexOf(QLatin1Char('/')); - if (slash == -1) - ret = QDir::currentPath(); - else if (slash == 0) - ret = QString(QLatin1Char('/')); - ret = ret.left(slash); - } - return ret; + if (file == CanonicalPathName) + return entry.path(); + return entry.filePath(); } else if (file == LinkName) { QString ret; if (d->fileEntry.filePath().endsWith(QLatin1String(".lnk"))) |