summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2010-02-01 06:02:59 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2010-02-01 06:02:59 (GMT)
commitdc1cab966938edc5463f26189607ece134549a22 (patch)
treeecaab6c64758f41fa9cb5b376b395831a77e6c83 /src/corelib/io
parent4915439de467d1119a46af66ea08dbe161d2f336 (diff)
parentbde40a9fa852107c237ac408f93a33b5955b9290 (diff)
downloadQt-dc1cab966938edc5463f26189607ece134549a22.zip
Qt-dc1cab966938edc5463f26189607ece134549a22.tar.gz
Qt-dc1cab966938edc5463f26189607ece134549a22.tar.bz2
Merge commit 'oslo1/master' into oslo1-master
Conflicts: doc/src/getting-started/installation.qdoc src/gui/dialogs/qfiledialog_win.cpp tools/assistant/tools/assistant/centralwidget.cpp tools/assistant/tools/assistant/helpviewer.cpp
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/io.pri2
-rw-r--r--src/corelib/io/qdataurl.cpp101
-rw-r--r--src/corelib/io/qdataurl_p.h67
-rw-r--r--src/corelib/io/qdir.cpp359
-rw-r--r--src/corelib/io/qdir.h5
-rw-r--r--src/corelib/io/qfileinfo.cpp303
-rw-r--r--src/corelib/io/qfileinfo_p.h21
-rw-r--r--src/corelib/io/qfilesystemwatcher.cpp2
-rw-r--r--src/corelib/io/qfilesystemwatcher_dnotify.cpp13
-rw-r--r--src/corelib/io/qfilesystemwatcher_fsevents.cpp10
-rw-r--r--src/corelib/io/qfsfileengine.cpp27
-rw-r--r--src/corelib/io/qfsfileengine_iterator_unix.cpp20
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp16
-rw-r--r--src/corelib/io/qurl.h7
14 files changed, 529 insertions, 424 deletions
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index 02a1586..2ed0e46 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -6,6 +6,7 @@ HEADERS += \
io/qbuffer.h \
io/qdatastream.h \
io/qdatastream_p.h \
+ io/qdataurl_p.h \
io/qdebug.h \
io/qdir.h \
io/qdiriterator.h \
@@ -34,6 +35,7 @@ SOURCES += \
io/qabstractfileengine.cpp \
io/qbuffer.cpp \
io/qdatastream.cpp \
+ io/qdataurl.cpp \
io/qdebug.cpp \
io/qdir.cpp \
io/qdiriterator.cpp \
diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp
new file mode 100644
index 0000000..9bb896e
--- /dev/null
+++ b/src/corelib/io/qdataurl.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformdefs.h"
+#include "qurl.h"
+#include "private/qdataurl_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+
+ Decode a data: URL into its mimetype and payload. Returns a null string if
+ the URL could not be decoded.
+*/
+Q_CORE_EXPORT QPair<QString, QByteArray> qDecodeDataUrl(const QUrl &uri)
+{
+ QString mimeType;
+ QByteArray payload;
+
+ if (uri.scheme() == QLatin1String("data") && uri.host().isEmpty()) {
+ mimeType = QLatin1String("text/plain;charset=US-ASCII");
+
+ // the following would have been the correct thing, but
+ // reality often differs from the specification. People have
+ // data: URIs with ? and #
+ //QByteArray data = QByteArray::fromPercentEncoding(uri.encodedPath());
+ QByteArray data = QByteArray::fromPercentEncoding(uri.toEncoded());
+
+ // remove the data: scheme
+ data.remove(0, 5);
+
+ // parse it:
+ int pos = data.indexOf(',');
+ if (pos != -1) {
+ payload = data.mid(pos + 1);
+ data.truncate(pos);
+ data = data.trimmed();
+
+ // find out if the payload is encoded in Base64
+ if (data.endsWith(";base64")) {
+ payload = QByteArray::fromBase64(payload);
+ data.chop(7);
+ }
+
+ if (data.toLower().startsWith("charset")) {
+ int i = 7; // strlen("charset")
+ while (data.at(i) == ' ')
+ ++i;
+ if (data.at(i) == '=')
+ data.prepend("text/plain;");
+ }
+
+ if (!data.isEmpty())
+ mimeType = QLatin1String(data.trimmed());
+
+ }
+ }
+
+ return QPair<QString,QByteArray>(mimeType,payload);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/io/qdataurl_p.h b/src/corelib/io/qdataurl_p.h
new file mode 100644
index 0000000..be5b10d
--- /dev/null
+++ b/src/corelib/io/qdataurl_p.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDATAURL_P_H
+#define QDATAURL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qDecodeDataUrl. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qurl.h"
+#include "QtCore/qbytearray.h"
+#include "QtCore/qstring.h"
+#include "QtCore/qpair.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_CORE_EXPORT QPair<QString, QByteArray> qDecodeDataUrl(const QUrl &url);
+
+QT_END_NAMESPACE
+
+#endif // QDATAURL_P_H
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index dc7f17e..250e5e5 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -52,13 +52,13 @@
#include "qregexp.h"
#include "qvector.h"
#include "qalgorithms.h"
+#include "qvarlengtharray.h"
+
#ifdef QT_BUILD_CORE_LIB
-# include "qresource.h"
+# include "qresource.h"
+# include "private/qcoreglobaldata_p.h"
#endif
-#include "qvarlengtharray.h"
-
-#include "private/qcoreglobaldata_p.h"
#include <stdlib.h>
QT_BEGIN_NAMESPACE
@@ -83,12 +83,10 @@ static QString driveSpec(const QString &path)
//************* QDirPrivate
class QDirPrivate
{
- QDir *q_ptr;
- Q_DECLARE_PUBLIC(QDir)
-
friend struct QScopedPointerDeleter<QDirPrivate>;
-protected:
- QDirPrivate(QDir*, const QDir *copy=0);
+
+public:
+ QDirPrivate(const QDir *copy = 0);
~QDirPrivate();
QString initFileEngine(const QString &file);
@@ -96,7 +94,6 @@ protected:
void updateFileLists() const;
void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *) const;
-private:
#ifdef QT3_SUPPORT
QChar filterSepChar;
bool matchAllDirs;
@@ -109,28 +106,30 @@ private:
sep = QChar(QLatin1Char(' '));
return sep;
}
- static inline QStringList splitFilters(const QString &nameFilter, QChar sep=0) {
- if(sep == 0)
+ static inline QStringList splitFilters(const QString &nameFilter, QChar sep = 0) {
+ if (sep == 0)
sep = getFilterSepChar(nameFilter);
QStringList ret = nameFilter.split(sep);
- for(int i = 0; i < ret.count(); i++)
+ for (int i = 0; i < ret.count(); ++i)
ret[i] = ret[i].trimmed();
return ret;
}
struct Data {
inline Data()
- : ref(1), fileEngine(0)
- { clear(); }
+ : ref(1), fileEngine(0), listsDirty(1)
+ {}
inline Data(const Data &copy)
: ref(1), path(copy.path), nameFilters(copy.nameFilters), sort(copy.sort),
- filters(copy.filters), fileEngine(0)
- { clear(); }
+ filters(copy.filters), fileEngine(0), listsDirty(1)
+ {}
inline ~Data()
{ delete fileEngine; }
inline void clear() {
listsDirty = 1;
+ files.clear();
+ fileInfos.clear();
}
mutable QAtomicInt ref;
@@ -147,7 +146,6 @@ private:
} *data;
inline void setPath(const QString &p)
{
- detach(false);
QString path = p;
if ((path.endsWith(QLatin1Char('/')) || path.endsWith(QLatin1Char('\\')))
&& path.length() > 1) {
@@ -156,12 +154,9 @@ private:
#endif
path.truncate(path.length() - 1);
}
- if(!data->fileEngine || !QDir::isRelativePath(path))
- path = initFileEngine(path);
- data->fileEngine->setFileName(path);
+
// set the path to be the qt friendly version so then we can operate on it using just /
- data->path = data->fileEngine->fileName(QAbstractFileEngine::DefaultName);
- data->clear();
+ data->path = initFileEngine(path);
}
inline void reset() {
detach();
@@ -170,18 +165,16 @@ private:
void detach(bool createFileEngine = true);
};
-QDirPrivate::QDirPrivate(QDir *qq, const QDir *copy) : q_ptr(qq)
+QDirPrivate::QDirPrivate(const QDir *copy)
#ifdef QT3_SUPPORT
- , filterSepChar(0)
- , matchAllDirs(false)
+ : filterSepChar(0), matchAllDirs(false)
#endif
{
- if(copy) {
+ if (copy) {
copy->d_func()->data->ref.ref();
data = copy->d_func()->data;
} else {
data = new QDirPrivate::Data;
- data->clear();
}
}
@@ -190,18 +183,19 @@ QDirPrivate::~QDirPrivate()
if (!data->ref.deref())
delete data;
data = 0;
- q_ptr = 0;
}
/* For sorting */
-struct QDirSortItem {
+struct QDirSortItem
+{
mutable QString filename_cache;
mutable QString suffix_cache;
QFileInfo item;
};
-class QDirSortItemComparator {
+class QDirSortItemComparator
+{
int qt_cmp_si_sort_flags;
public:
QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {}
@@ -240,7 +234,7 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt
f2->suffix_cache = ic ? f2->item.suffix().toLower()
: f2->item.suffix();
- r = qt_cmp_si_sort_flags & QDir::LocaleAware
+ r = qt_cmp_si_sort_flags & QDir::LocaleAware
? f1->suffix_cache.localeAwareCompare(f2->suffix_cache)
: f1->suffix_cache.compare(f2->suffix_cache);
}
@@ -260,7 +254,7 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt
f2->filename_cache = ic ? f2->item.fileName().toLower()
: f2->item.fileName();
- r = qt_cmp_si_sort_flags & QDir::LocaleAware
+ r = qt_cmp_si_sort_flags & QDir::LocaleAware
? f1->filename_cache.localeAwareCompare(f2->filename_cache)
: f1->filename_cache.compare(f2->filename_cache);
}
@@ -274,16 +268,13 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt
inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l,
QStringList *names, QFileInfoList *infos) const
{
- if(names)
- names->clear();
- if(infos)
- infos->clear();
+ // names and infos are always empty lists or 0 here
int n = l.size();
- if(n > 0) {
+ if (n > 0) {
if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) {
- if(infos)
+ if (infos)
*infos = l;
- if(names) {
+ if (names) {
for (int i = 0; i < n; ++i)
names->append(l.at(i).fileName());
}
@@ -291,13 +282,13 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l,
QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]);
for (int i = 0; i < n; ++i)
si[i].item = l.at(i);
- qSort(si.data(), si.data()+n, QDirSortItemComparator(sort));
+ qSort(si.data(), si.data() + n, QDirSortItemComparator(sort));
// put them back in the list(s)
- if(infos) {
+ if (infos) {
for (int i = 0; i < n; ++i)
infos->append(si[i].item);
}
- if(names) {
+ if (names) {
for (int i = 0; i < n; ++i)
names->append(si[i].item.fileName());
}
@@ -307,7 +298,7 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l,
inline void QDirPrivate::updateFileLists() const
{
- if(data->listsDirty) {
+ if (data->listsDirty) {
QFileInfoList l;
QDirIterator it(data->path, data->nameFilters, data->filters);
while (it.hasNext()) {
@@ -319,12 +310,11 @@ inline void QDirPrivate::updateFileLists() const
}
}
-QString QDirPrivate::initFileEngine(const QString &path)
+inline QString QDirPrivate::initFileEngine(const QString &path)
{
detach(false);
- delete data->fileEngine;
- data->fileEngine = 0;
data->clear();
+ delete data->fileEngine;
data->fileEngine = QAbstractFileEngine::create(path);
return data->fileEngine->fileName(QAbstractFileEngine::DefaultName);
}
@@ -520,8 +510,7 @@ void QDirPrivate::detach(bool createFileEngine)
\sa currentPath()
*/
-
-QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(this))
+QDir::QDir(const QString &path) : d_ptr(new QDirPrivate)
{
Q_D(QDir);
d->setPath(path.isEmpty() ? QString::fromLatin1(".") : path);
@@ -548,18 +537,17 @@ QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(this))
\sa exists(), setPath(), setNameFilter(), setFilter(), setSorting()
*/
-
QDir::QDir(const QString &path, const QString &nameFilter,
- SortFlags sort, Filters filters) : d_ptr(new QDirPrivate(this))
+ SortFlags sort, Filters filters) : d_ptr(new QDirPrivate)
{
Q_D(QDir);
d->setPath(path.isEmpty() ? QString::fromLatin1(".") : path);
d->data->nameFilters = QDir::nameFiltersFromString(nameFilter);
bool empty = d->data->nameFilters.isEmpty();
- if(!empty) {
+ if (!empty) {
empty = true;
- for(int i = 0; i < d->data->nameFilters.size(); ++i) {
- if(!d->data->nameFilters.at(i).isEmpty()) {
+ for (int i = 0; i < d->data->nameFilters.size(); ++i) {
+ if (!d->data->nameFilters.at(i).isEmpty()) {
empty = false;
break;
}
@@ -577,8 +565,7 @@ QDir::QDir(const QString &path, const QString &nameFilter,
\sa operator=()
*/
-
-QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(this, &dir))
+QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(&dir))
{
}
@@ -586,7 +573,6 @@ QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(this, &dir))
Destroys the QDir object frees up its resources. This has no
effect on the underlying directory in the file system.
*/
-
QDir::~QDir()
{
}
@@ -607,7 +593,6 @@ QDir::~QDir()
\sa path(), absolutePath(), exists(), cleanPath(), dirName(),
absoluteFilePath(), isRelative(), makeAbsolute()
*/
-
void QDir::setPath(const QString &path)
{
Q_D(QDir);
@@ -624,7 +609,6 @@ void QDir::setPath(const QString &path)
\sa setPath(), absolutePath(), exists(), cleanPath(), dirName(),
absoluteFilePath(), toNativeSeparators(), makeAbsolute()
*/
-
QString QDir::path() const
{
Q_D(const QDir);
@@ -639,7 +623,6 @@ QString QDir::path() const
\sa setPath(), canonicalPath(), exists(), cleanPath(),
dirName(), absoluteFilePath()
*/
-
QString QDir::absolutePath() const
{
Q_D(const QDir);
@@ -649,7 +632,6 @@ QString QDir::absolutePath() const
return cleanPath(ret);
}
-
/*!
Returns the canonical path, i.e. a path without symbolic links or
redundant "." or ".." elements.
@@ -666,12 +648,11 @@ QString QDir::absolutePath() const
\sa path(), absolutePath(), exists(), cleanPath(), dirName(),
absoluteFilePath()
*/
-
QString QDir::canonicalPath() const
{
Q_D(const QDir);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return cleanPath(d->data->fileEngine->fileName(QAbstractFileEngine::CanonicalName));
}
@@ -687,7 +668,6 @@ QString QDir::canonicalPath() const
\sa path(), filePath(), absolutePath(), absoluteFilePath()
*/
-
QString QDir::dirName() const
{
Q_D(const QDir);
@@ -706,7 +686,6 @@ QString QDir::dirName() const
\sa dirName() absoluteFilePath(), isRelative(), canonicalPath()
*/
-
QString QDir::filePath(const QString &fileName) const
{
Q_D(const QDir);
@@ -714,7 +693,7 @@ QString QDir::filePath(const QString &fileName) const
return QString(fileName);
QString ret = d->data->path;
- if(!fileName.isEmpty()) {
+ if (!fileName.isEmpty()) {
if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/'))
ret += QLatin1Char('/');
ret += fileName;
@@ -730,13 +709,12 @@ QString QDir::filePath(const QString &fileName) const
\sa relativeFilePath() filePath() canonicalPath()
*/
-
QString QDir::absoluteFilePath(const QString &fileName) const
{
Q_D(const QDir);
if (isAbsolutePath(fileName))
return fileName;
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return fileName;
QString ret;
@@ -744,7 +722,7 @@ QString QDir::absoluteFilePath(const QString &fileName) const
if (isRelativePath(d->data->path)) //get pwd
ret = QFSFileEngine::currentPath(fileName);
#endif
- if(!d->data->path.isEmpty() && d->data->path != QLatin1String(".")) {
+ if (!d->data->path.isEmpty() && d->data->path != QLatin1String(".")) {
if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/')))
ret += QLatin1Char('/');
ret += d->data->path;
@@ -764,7 +742,6 @@ QString QDir::absoluteFilePath(const QString &fileName) const
\sa absoluteFilePath() filePath() canonicalPath()
*/
-
QString QDir::relativeFilePath(const QString &fileName) const
{
QString dir = absolutePath();
@@ -851,7 +828,7 @@ QString QDir::toNativeSeparators(const QString &pathName)
{
QString n(pathName);
#if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
- for (int i=0; i<(int)n.length(); i++) {
+ for (int i = 0; i < (int)n.length(); ++i) {
if (n[i] == QLatin1Char('/'))
n[i] = QLatin1Char('\\');
}
@@ -875,7 +852,7 @@ QString QDir::fromNativeSeparators(const QString &pathName)
{
QString n(pathName);
#if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
- for (int i=0; i<(int)n.length(); i++) {
+ for (int i = 0; i < (int)n.length(); ++i) {
if (n[i] == QLatin1Char('\\'))
n[i] = QLatin1Char('/');
}
@@ -894,7 +871,6 @@ QString QDir::fromNativeSeparators(const QString &pathName)
\sa cdUp(), isReadable(), exists(), path()
*/
-
bool QDir::cd(const QString &dirName)
{
Q_D(QDir);
@@ -930,14 +906,13 @@ bool QDir::cd(const QString &dirName)
}
}
}
- {
- QFileInfo fi(newPath);
- if (!(fi.exists() && fi.isDir()))
- return false;
- }
- d->setPath(newPath);
- refresh();
+ QDir dir(*this);
+ dir.setPath(newPath);
+ if (!dir.exists())
+ return false;
+
+ *this = dir;
return true;
}
@@ -951,7 +926,6 @@ bool QDir::cd(const QString &dirName)
\sa cd(), isReadable(), exists(), path()
*/
-
bool QDir::cdUp()
{
return cd(QString::fromLatin1(".."));
@@ -960,7 +934,6 @@ bool QDir::cdUp()
/*!
Returns the string list set by setNameFilters()
*/
-
QStringList QDir::nameFilters() const
{
Q_D(const QDir);
@@ -983,10 +956,10 @@ QStringList QDir::nameFilters() const
\sa nameFilters(), setFilter()
*/
-
void QDir::setNameFilters(const QStringList &nameFilters)
{
Q_D(QDir);
+
d->detach();
d->data->nameFilters = nameFilters;
}
@@ -1001,7 +974,6 @@ void QDir::setNameFilters(const QStringList &nameFilters)
\sa {The Qt Resource System}, QResource::addSearchPath()
*/
-
void QDir::addResourceSearchPath(const QString &path)
{
#ifdef QT_BUILD_CORE_LIB
@@ -1039,7 +1011,7 @@ void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths)
return;
}
- for (int i = 0; i < prefix.count(); i++) {
+ for (int i = 0; i < prefix.count(); ++i) {
if (!prefix.at(i).isLetterOrNumber()) {
qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
return;
@@ -1089,7 +1061,6 @@ QStringList QDir::searchPaths(const QString &prefix)
/*!
Returns the value set by setFilter()
*/
-
QDir::Filters QDir::filter() const
{
Q_D(const QDir);
@@ -1171,7 +1142,6 @@ QDir::Filters QDir::filter() const
\sa filter(), setNameFilters()
*/
-
void QDir::setFilter(Filters filters)
{
Q_D(QDir);
@@ -1185,7 +1155,6 @@ void QDir::setFilter(Filters filters)
\sa setSorting() SortFlag
*/
-
QDir::SortFlags QDir::sorting() const
{
Q_D(const QDir);
@@ -1231,7 +1200,6 @@ QDir::SortFlags QDir::sorting() const
\sa sorting() SortFlag
*/
-
void QDir::setSorting(SortFlags sort)
{
Q_D(QDir);
@@ -1240,7 +1208,6 @@ void QDir::setSorting(SortFlags sort)
d->data->sort = sort;
}
-
/*!
Returns the total number of directories and files in the directory.
@@ -1248,7 +1215,6 @@ void QDir::setSorting(SortFlags sort)
\sa operator[](), entryList()
*/
-
uint QDir::count() const
{
Q_D(const QDir);
@@ -1260,13 +1226,10 @@ uint QDir::count() const
/*!
Returns the file name at position \a pos in the list of file
names. Equivalent to entryList().at(index).
-
- Returns an empty string if \a pos is out of range or if the
- entryList() function failed.
+ \a pos must be a valid index position in the list (i.e., 0 <= pos < count()).
\sa count(), entryList()
*/
-
QString QDir::operator[](int pos) const
{
Q_D(const QDir);
@@ -1294,7 +1257,6 @@ QString QDir::operator[](int pos) const
\sa entryInfoList(), setNameFilters(), setSorting(), setFilter()
*/
-
QStringList QDir::entryList(Filters filters, SortFlags sort) const
{
Q_D(const QDir);
@@ -1342,7 +1304,6 @@ QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const
\sa entryInfoList(), setNameFilters(), setSorting(), setFilter()
*/
-
QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,
SortFlags sort) const
{
@@ -1356,10 +1317,12 @@ QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,
#endif
if (sort == NoSort)
sort = d->data->sort;
- if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) {
+
+ if (filters == d->data->filters && sort == d->data->sort && nameFilters == d->data->nameFilters) {
d->updateFileLists();
return d->data->files;
}
+
QFileInfoList l;
QDirIterator it(d->data->path, nameFilters, filters);
while (it.hasNext()) {
@@ -1387,7 +1350,6 @@ QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,
\sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()
*/
-
QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters,
SortFlags sort) const
{
@@ -1401,10 +1363,12 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter
#endif
if (sort == NoSort)
sort = d->data->sort;
- if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) {
+
+ if (filters == d->data->filters && sort == d->data->sort && nameFilters == d->data->nameFilters) {
d->updateFileLists();
return d->data->fileInfos;
}
+
QFileInfoList l;
QDirIterator it(d->data->path, nameFilters, filters);
while (it.hasNext()) {
@@ -1423,7 +1387,6 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter
\sa rmdir()
*/
-
bool QDir::mkdir(const QString &dirName) const
{
Q_D(const QDir);
@@ -1432,7 +1395,7 @@ bool QDir::mkdir(const QString &dirName) const
qWarning("QDir::mkdir: Empty or null file name(s)");
return false;
}
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
QString fn = filePath(dirName);
@@ -1448,7 +1411,6 @@ bool QDir::mkdir(const QString &dirName) const
\sa mkdir()
*/
-
bool QDir::rmdir(const QString &dirName) const
{
Q_D(const QDir);
@@ -1457,7 +1419,7 @@ bool QDir::rmdir(const QString &dirName) const
qWarning("QDir::rmdir: Empty or null file name(s)");
return false;
}
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
QString fn = filePath(dirName);
@@ -1474,7 +1436,6 @@ bool QDir::rmdir(const QString &dirName) const
\sa rmpath()
*/
-
bool QDir::mkpath(const QString &dirPath) const
{
Q_D(const QDir);
@@ -1483,7 +1444,7 @@ bool QDir::mkpath(const QString &dirPath) const
qWarning("QDir::mkpath: Empty or null file name(s)");
return false;
}
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
QString fn = filePath(dirPath);
@@ -1509,7 +1470,7 @@ bool QDir::rmpath(const QString &dirPath) const
qWarning("QDir::rmpath: Empty or null file name(s)");
return false;
}
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
QString fn = filePath(dirPath);
@@ -1525,17 +1486,16 @@ bool QDir::rmpath(const QString &dirPath) const
\sa QFileInfo::isReadable()
*/
-
-
bool QDir::isReadable() const
{
Q_D(const QDir);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
- const QAbstractFileEngine::FileFlags info = d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
- |QAbstractFileEngine::PermsMask);
- if(!(info & QAbstractFileEngine::DirectoryType))
+ const QAbstractFileEngine::FileFlags info =
+ d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
+ | QAbstractFileEngine::PermsMask);
+ if (!(info & QAbstractFileEngine::DirectoryType))
return false;
return info & QAbstractFileEngine::ReadUserPerm;
}
@@ -1551,19 +1511,17 @@ bool QDir::isReadable() const
\sa QFileInfo::exists(), QFile::exists()
*/
-
bool QDir::exists() const
{
Q_D(const QDir);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
const QAbstractFileEngine::FileFlags info =
- d->data->fileEngine->fileFlags(
- QAbstractFileEngine::DirectoryType
- | QAbstractFileEngine::ExistsFlag
- | QAbstractFileEngine::Refresh);
- if(!(info & QAbstractFileEngine::DirectoryType))
+ d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
+ | QAbstractFileEngine::ExistsFlag
+ | QAbstractFileEngine::Refresh);
+ if (!(info & QAbstractFileEngine::DirectoryType))
return false;
return info & QAbstractFileEngine::ExistsFlag;
}
@@ -1580,12 +1538,11 @@ bool QDir::exists() const
\sa root(), rootPath()
*/
-
bool QDir::isRoot() const
{
Q_D(const QDir);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return true;
return d->data->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
}
@@ -1615,12 +1572,11 @@ bool QDir::isRoot() const
\sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath()
*/
-
bool QDir::isRelative() const
{
Q_D(const QDir);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->data->fileEngine->isRelativePath();
}
@@ -1633,20 +1589,19 @@ bool QDir::isRelative() const
\sa isAbsolute() isAbsolutePath() isRelative() cleanPath()
*/
-
bool QDir::makeAbsolute() // ### What do the return values signify?
{
Q_D(QDir);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
QString absolutePath = d->data->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
- if(QDir::isRelativePath(absolutePath))
+ if (QDir::isRelativePath(absolutePath))
return false;
d->detach();
d->data->path = absolutePath;
d->data->fileEngine->setFileName(absolutePath);
- if(!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType))
+ if (!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType))
return false;
return true;
}
@@ -1660,22 +1615,21 @@ bool QDir::makeAbsolute() // ### What do the return values signify?
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 10
*/
-
bool QDir::operator==(const QDir &dir) const
{
const QDirPrivate *d = d_func();
const QDirPrivate *other = dir.d_func();
- if(d->data == other->data)
+ if (d->data == other->data)
return true;
Q_ASSERT(d->data->fileEngine && other->data->fileEngine);
- if(d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive())
+ if (d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive())
return false;
- if(d->data->filters == other->data->filters
+ if (d->data->filters == other->data->filters
&& d->data->sort == other->data->sort
&& d->data->nameFilters == other->data->nameFilters) {
QString dir1 = absolutePath(), dir2 = dir.absolutePath();
- if(!other->data->fileEngine->caseSensitive())
+ if (!other->data->fileEngine->caseSensitive())
return (dir1.toLower() == dir2.toLower());
return (dir1 == dir2);
@@ -1688,7 +1642,6 @@ bool QDir::operator==(const QDir &dir) const
Makes a copy of the \a dir object and assigns it to this QDir
object.
*/
-
QDir &QDir::operator=(const QDir &dir)
{
if (this == &dir)
@@ -1707,7 +1660,6 @@ QDir &QDir::operator=(const QDir &dir)
Use setPath() instead.
*/
-
QDir &QDir::operator=(const QString &path)
{
Q_D(QDir);
@@ -1728,22 +1680,19 @@ QDir &QDir::operator=(const QString &path)
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 11
*/
-
/*!
Removes the file, \a fileName.
Returns true if the file is removed successfully; otherwise
returns false.
*/
-
bool QDir::remove(const QString &fileName)
{
if (fileName.isEmpty()) {
qWarning("QDir::remove: Empty or null file name");
return false;
}
- QString p = filePath(fileName);
- return QFile::remove(p);
+ return QFile::remove(filePath(fileName));
}
/*!
@@ -1757,7 +1706,6 @@ bool QDir::remove(const QString &fileName)
fail. For example, on at least one file system rename() fails if
\a newName points to an open file.
*/
-
bool QDir::rename(const QString &oldName, const QString &newName)
{
Q_D(QDir);
@@ -1766,11 +1714,11 @@ bool QDir::rename(const QString &oldName, const QString &newName)
qWarning("QDir::rename: Empty or null file name(s)");
return false;
}
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
QFile file(filePath(oldName));
- if(!file.exists())
+ if (!file.exists())
return false;
return file.rename(filePath(newName));
}
@@ -1785,15 +1733,13 @@ bool QDir::rename(const QString &oldName, const QString &newName)
\sa QFileInfo::exists(), QFile::exists()
*/
-
bool QDir::exists(const QString &name) const
{
if (name.isEmpty()) {
qWarning("QDir::exists: Empty or null file name");
return false;
}
- QString tmp = filePath(name);
- return QFile::exists(tmp);
+ return QFile::exists(filePath(name));
}
/*!
@@ -1805,7 +1751,6 @@ bool QDir::exists(const QString &name) const
\sa root(), rootPath()
*/
-
QFileInfoList QDir::drives()
{
#ifdef QT_NO_FSFILEENGINE
@@ -1825,7 +1770,6 @@ QFileInfoList QDir::drives()
user using their operating system's separator use
toNativeSeparators().
*/
-
QChar QDir::separator()
{
#if defined (Q_FS_FAT) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
@@ -1844,9 +1788,8 @@ QChar QDir::separator()
Returns true if the directory was successfully changed; otherwise
returns false.
- \sa current() currentPath() home() root() temp()
+ \sa current(), currentPath(), home(), root(), temp()
*/
-
bool QDir::setCurrent(const QString &path)
{
#ifdef QT_NO_FSFILEENGINE
@@ -1865,13 +1808,13 @@ bool QDir::setCurrent(const QString &path)
The directory is constructed using the absolute path of the current directory,
ensuring that its path() will be the same as its absolutePath().
- \sa currentPath(), home(), root(), temp()
+ \sa currentPath(), setCurrent(), home(), root(), temp()
*/
/*!
Returns the absolute path of the application's current directory.
- \sa current(), homePath(), rootPath(), tempPath()
+ \sa current(), setCurrent(), homePath(), rootPath(), tempPath()
*/
QString QDir::currentPath()
{
@@ -1888,7 +1831,7 @@ QString QDir::currentPath()
Use currentPath() instead.
- \sa currentPath()
+ \sa currentPath(), setCurrent()
*/
/*!
@@ -1945,14 +1888,14 @@ QString QDir::homePath()
}
/*!
- \fn QString QDir::homeDirPath()
+ \fn QString QDir::homeDirPath()
- Returns the absolute path of the user's home directory.
+ Returns the absolute path of the user's home directory.
- Use homePath() instead.
+ Use homePath() instead.
- \sa homePath()
- */
+ \sa homePath()
+*/
/*!
\fn QDir QDir::temp()
@@ -2018,13 +1961,13 @@ QString QDir::rootPath()
}
/*!
- \fn QString QDir::rootDirPath()
+ \fn QString QDir::rootDirPath()
- Returns the absolute path of the root directory.
+ Returns the absolute path of the root directory.
- Use rootPath() instead.
+ Use rootPath() instead.
- \sa rootPath()
+ \sa rootPath()
*/
#ifndef QT_NO_REGEXP
@@ -2037,11 +1980,9 @@ QString QDir::rootPath()
\sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()
*/
-
-
bool QDir::match(const QStringList &filters, const QString &fileName)
{
- for(QStringList::ConstIterator sit = filters.begin(); sit != filters.end(); ++sit) {
+ for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) {
QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard);
if (rx.exactMatch(fileName))
return true;
@@ -2057,12 +1998,11 @@ bool QDir::match(const QStringList &filters, const QString &fileName)
\sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()
*/
-
bool QDir::match(const QString &filter, const QString &fileName)
{
return match(nameFiltersFromString(filter), fileName);
}
-#endif
+#endif // QT_NO_REGEXP
/*!
Removes all multiple directory separators "/" and resolves any
@@ -2075,15 +2015,14 @@ bool QDir::match(const QString &filter, const QString &fileName)
\sa absolutePath() canonicalPath()
*/
-
QString QDir::cleanPath(const QString &path)
{
if (path.isEmpty())
return path;
QString name = path;
QChar dir_separator = separator();
- if(dir_separator != QLatin1Char('/'))
- name.replace(dir_separator, QLatin1Char('/'));
+ if (dir_separator != QLatin1Char('/'))
+ name.replace(dir_separator, QLatin1Char('/'));
int used = 0, levels = 0;
const int len = name.length();
@@ -2091,27 +2030,27 @@ QString QDir::cleanPath(const QString &path)
QChar *out = outVector.data();
const QChar *p = name.unicode();
- for(int i = 0, last = -1, iwrite = 0; i < len; i++) {
- if(p[i] == QLatin1Char('/')) {
- while(i < len-1 && p[i+1] == QLatin1Char('/')) {
+ for (int i = 0, last = -1, iwrite = 0; i < len; ++i) {
+ if (p[i] == QLatin1Char('/')) {
+ while (i < len-1 && p[i+1] == QLatin1Char('/')) {
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths
- if(!i)
+ if (!i)
break;
#endif
i++;
}
bool eaten = false;
- if(i < len - 1 && p[i+1] == QLatin1Char('.')) {
+ if (i < len - 1 && p[i+1] == QLatin1Char('.')) {
int dotcount = 1;
- if(i < len - 2 && p[i+2] == QLatin1Char('.'))
+ if (i < len - 2 && p[i+2] == QLatin1Char('.'))
dotcount++;
- if(i == len - dotcount - 1) {
- if(dotcount == 1) {
+ if (i == len - dotcount - 1) {
+ if (dotcount == 1) {
break;
- } else if(levels) {
- if(last == -1) {
- for(int i2 = iwrite-1; i2 >= 0; i2--) {
- if(out[i2] == QLatin1Char('/')) {
+ } else if (levels) {
+ if (last == -1) {
+ for (int i2 = iwrite-1; i2 >= 0; i2--) {
+ if (out[i2] == QLatin1Char('/')) {
last = i2;
break;
}
@@ -2120,11 +2059,11 @@ QString QDir::cleanPath(const QString &path)
used -= iwrite - last - 1;
break;
}
- } else if(p[i+dotcount+1] == QLatin1Char('/')) {
- if(dotcount == 2 && levels) {
- if(last == -1 || iwrite - last == 1) {
- for(int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) {
- if(out[i2] == QLatin1Char('/')) {
+ } else if (p[i+dotcount+1] == QLatin1Char('/')) {
+ if (dotcount == 2 && levels) {
+ if (last == -1 || iwrite - last == 1) {
+ for (int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) {
+ if (out[i2] == QLatin1Char('/')) {
eaten = true;
last = i2;
break;
@@ -2133,7 +2072,7 @@ QString QDir::cleanPath(const QString &path)
} else {
eaten = true;
}
- if(eaten) {
+ if (eaten) {
levels--;
used -= iwrite - last;
iwrite = last;
@@ -2145,38 +2084,38 @@ QString QDir::cleanPath(const QString &path)
iwrite = qMax(0, last);
last = -1;
++i;
- } else if(dotcount == 1) {
+ } else if (dotcount == 1) {
eaten = true;
}
- if(eaten)
+ if (eaten)
i += dotcount;
} else {
levels++;
}
- } else if(last != -1 && iwrite - last == 1) {
+ } else if (last != -1 && iwrite - last == 1) {
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
eaten = (iwrite > 2);
#else
eaten = true;
#endif
last = -1;
- } else if(last != -1 && i == len-1) {
+ } else if (last != -1 && i == len-1) {
eaten = true;
} else {
levels++;
}
- if(!eaten)
+ if (!eaten)
last = i - (i - iwrite);
else
continue;
- } else if(!i && p[i] == QLatin1Char('.')) {
+ } else if (!i && p[i] == QLatin1Char('.')) {
int dotcount = 1;
- if(len >= 1 && p[1] == QLatin1Char('.'))
+ if (len >= 1 && p[1] == QLatin1Char('.'))
dotcount++;
- if(len >= dotcount && p[dotcount] == QLatin1Char('/')) {
- if(dotcount == 1) {
+ if (len >= dotcount && p[dotcount] == QLatin1Char('/')) {
+ if (dotcount == 1) {
i++;
- while(i+1 < len-1 && p[i+1] == QLatin1Char('/'))
+ while (i+1 < len-1 && p[i+1] == QLatin1Char('/'))
i++;
continue;
}
@@ -2185,16 +2124,15 @@ QString QDir::cleanPath(const QString &path)
out[iwrite++] = p[i];
used++;
}
- QString ret;
- if(used == len)
- ret = name;
- else
- ret = QString(out, used);
+ QString ret = (used == len ? name : QString(out, used));
// Strip away last slash except for root directories
- if (ret.endsWith(QLatin1Char('/'))
- && !(ret.size() == 1 || (ret.size() == 3 && ret.at(1) == QLatin1Char(':'))))
- ret = ret.left(ret.length() - 1);
+ if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
+#ifdef Q_OS_WIN
+ if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':')))
+#endif
+ ret.chop(1);
+ }
return ret;
}
@@ -2205,7 +2143,6 @@ QString QDir::cleanPath(const QString &path)
\sa isRelative() isAbsolutePath() makeAbsolute()
*/
-
bool QDir::isRelativePath(const QString &path)
{
return QFileInfo(path).isRelative();
@@ -2214,7 +2151,6 @@ bool QDir::isRelativePath(const QString &path)
/*!
Refreshes the directory information.
*/
-
void QDir::refresh() const
{
Q_D(const QDir);
@@ -2229,7 +2165,6 @@ void QDir::refresh() const
there is more than one filter, each pair of filters is separated
by a space or by a semicolon.)
*/
-
QStringList QDir::nameFiltersFromString(const QString &nameFilter)
{
return QDirPrivate::splitFilters(nameFilter);
@@ -2421,7 +2356,8 @@ void QDir::setNameFilter(const QString &nameFilter)
Use QDir::SortFlags instead.
*/
-#endif
+#endif // QT3_SUPPORT
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, QDir::Filters filters)
{
@@ -2484,9 +2420,6 @@ QDebug operator<<(QDebug debug, const QDir &dir)
<< ')';
return debug.space();
}
-
-
-
-#endif
+#endif // QT_NO_DEBUG_STREAM
QT_END_NAMESPACE
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h
index 6be4922..186dd2f 100644
--- a/src/corelib/io/qdir.h
+++ b/src/corelib/io/qdir.h
@@ -83,7 +83,7 @@ public:
Modified = 0x080,
Hidden = 0x100,
System = 0x200,
-
+
AccessMask = 0x3F0,
AllDirs = 0x400,
@@ -215,6 +215,7 @@ public:
static bool match(const QStringList &filters, const QString &fileName);
static bool match(const QString &filter, const QString &fileName);
#endif
+
static QString cleanPath(const QString &path);
void refresh() const;
@@ -246,7 +247,7 @@ public:
inline QT3_SUPPORT static QString homeDirPath() { return homePath(); }
inline QT3_SUPPORT static QString rootDirPath() { return rootPath(); }
inline QT3_SUPPORT static QString cleanDirPath(const QString &name) { return cleanPath(name); }
-#endif
+#endif // QT3_SUPPORT
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index e90529e..625098e 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -41,12 +41,8 @@
#include "qplatformdefs.h"
#include "qfileinfo.h"
-#include "qdatetime.h"
-#include "qabstractfileengine.h"
#include "qfsfileengine_p.h"
#include "qglobal.h"
-#include "qatomic.h"
-#include "qhash.h"
#include "qdir.h"
#include "qfileinfo_p.h"
@@ -54,7 +50,7 @@ QT_BEGIN_NAMESPACE
QFileInfoPrivate::QFileInfoPrivate(const QFileInfo *copy)
{
- if(copy) {
+ if (copy) {
copy->d_func()->data->ref.ref();
data = copy->d_func()->data;
} else {
@@ -81,7 +77,8 @@ void QFileInfoPrivate::initFileEngine(const QString &file)
bool QFileInfoPrivate::hasAccess(Access access) const
{
- if (!(getFileFlags(QAbstractFileEngine::FileInfoAll) & QAbstractFileEngine::LocalDiskFlag)) {
+ if (!(getFileFlags(QAbstractFileEngine::PermsMask
+ | QAbstractFileEngine::LocalDiskFlag) & QAbstractFileEngine::LocalDiskFlag)) {
switch (access) {
case ReadAccess:
return getFileFlags(QAbstractFileEngine::ReadUserPerm);
@@ -129,86 +126,104 @@ void QFileInfoPrivate::detach()
QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const
{
- if(data->cache_enabled && !data->fileNames[(int)name].isNull())
+ if (data->cache_enabled && !data->fileNames[(int)name].isNull())
return data->fileNames[(int)name];
QString ret = data->fileEngine->fileName(name);
- if(data->cache_enabled)
+ if (ret.isNull())
+ ret = QLatin1String("");
+ if (data->cache_enabled)
data->fileNames[(int)name] = ret;
return ret;
}
+QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const
+{
+ if (data->cache_enabled && !data->fileOwners[(int)own].isNull())
+ return data->fileOwners[(int)own];
+ QString ret = data->fileEngine->owner(own);
+ if (ret.isNull())
+ ret = QLatin1String("");
+ if (data->cache_enabled)
+ data->fileOwners[(int)own] = ret;
+ return ret;
+}
+
uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) const
{
- // We split the testing into tests for for LinkType, BundleType and the rest.
+ // We split the testing into tests for for LinkType, BundleType, PermsMask
+ // and the rest.
+ // Tests for file permissions on Windows can be slow, expecially on network
+ // paths and NTFS drives.
// In order to determine if a file is a symlink or not, we have to lstat().
// If we're not interested in that information, we might as well avoid one
// extra syscall. Bundle detecton on Mac can be slow, expecially on network
// paths, so we separate out that as well.
- QAbstractFileEngine::FileFlags flags;
- if (!data->getCachedFlag(CachedFileFlags)) {
- QAbstractFileEngine::FileFlags req = QAbstractFileEngine::FileInfoAll;
- req &= (~QAbstractFileEngine::LinkType);
- req &= (~QAbstractFileEngine::BundleType);
+ QAbstractFileEngine::FileFlags req = 0;
+ uint cachedFlags = 0;
- flags = data->fileEngine->fileFlags(req);
- data->setCachedFlag(CachedFileFlags);
- data->fileFlags |= uint(flags);
- } else {
- flags = QAbstractFileEngine::FileFlags(data->fileFlags & request);
- }
+ if (request & (QAbstractFileEngine::FlagsMask | QAbstractFileEngine::TypesMask)) {
+ if (!data->getCachedFlag(CachedFileFlags)) {
+ req |= QAbstractFileEngine::FlagsMask;
+ req |= QAbstractFileEngine::TypesMask;
+ req &= (~QAbstractFileEngine::LinkType);
+ req &= (~QAbstractFileEngine::BundleType);
- if (request & QAbstractFileEngine::LinkType) {
- if (!data->getCachedFlag(CachedLinkTypeFlag)) {
- QAbstractFileEngine::FileFlags linkflag;
- linkflag = data->fileEngine->fileFlags(QAbstractFileEngine::LinkType);
+ cachedFlags |= CachedFileFlags;
+ }
- data->setCachedFlag(CachedLinkTypeFlag);
- data->fileFlags |= uint(linkflag);
- flags |= linkflag;
+ if (request & QAbstractFileEngine::LinkType) {
+ if (!data->getCachedFlag(CachedLinkTypeFlag)) {
+ req |= QAbstractFileEngine::LinkType;
+ cachedFlags |= CachedLinkTypeFlag;
+ }
}
- }
- if (request & QAbstractFileEngine::BundleType) {
- if (!data->getCachedFlag(CachedBundleTypeFlag)) {
- QAbstractFileEngine::FileFlags bundleflag;
- bundleflag = data->fileEngine->fileFlags(QAbstractFileEngine::BundleType);
+ if (request & QAbstractFileEngine::BundleType) {
+ if (!data->getCachedFlag(CachedBundleTypeFlag)) {
+ req |= QAbstractFileEngine::BundleType;
+ cachedFlags |= CachedBundleTypeFlag;
+ }
+ }
+ }
- data->setCachedFlag(CachedBundleTypeFlag);
- data->fileFlags |= uint(bundleflag);
- flags |= bundleflag;
+ if (request & QAbstractFileEngine::PermsMask) {
+ if (!data->getCachedFlag(CachedPerms)) {
+ req |= QAbstractFileEngine::PermsMask;
+ cachedFlags |= CachedPerms;
}
}
- // no else branch
- // if we had it cached, it was caught in the previous else branch
+ if (req) {
+ if (data->cache_enabled)
+ req &= (~QAbstractFileEngine::Refresh);
+ else
+ req |= QAbstractFileEngine::Refresh;
- return flags & request;
+ QAbstractFileEngine::FileFlags flags = data->fileEngine->fileFlags(req);
+ data->fileFlags |= uint(flags);
+ data->setCachedFlag(cachedFlags);
+ }
+
+ return data->fileFlags & request;
}
QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) const
{
if (!data->cache_enabled)
data->clearFlags();
- if(request == QAbstractFileEngine::CreationTime) {
- if(data->getCachedFlag(CachedCTime))
- return data->fileTimes[request];
- data->setCachedFlag(CachedCTime);
- return (data->fileTimes[request] = data->fileEngine->fileTime(request));
+ uint cf;
+ if (request == QAbstractFileEngine::CreationTime)
+ cf = CachedCTime;
+ else if (request == QAbstractFileEngine::ModificationTime)
+ cf = CachedMTime;
+ else
+ cf = CachedATime;
+ if (!data->getCachedFlag(cf)) {
+ data->fileTimes[request] = data->fileEngine->fileTime(request);
+ data->setCachedFlag(cf);
}
- if(request == QAbstractFileEngine::ModificationTime) {
- if(data->getCachedFlag(CachedMTime))
- return data->fileTimes[request];
- data->setCachedFlag(CachedMTime);
- return (data->fileTimes[request] = data->fileEngine->fileTime(request));
- }
- if(request == QAbstractFileEngine::AccessTime) {
- if(data->getCachedFlag(CachedATime))
- return data->fileTimes[request];
- data->setCachedFlag(CachedATime);
- return (data->fileTimes[request] = data->fileEngine->fileTime(request));
- }
- return data->fileTimes[0]; //cannot really happen
+ return data->fileTimes[request];
}
//************* QFileInfo
@@ -305,7 +320,6 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request)
\sa setFile()
*/
-
QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate())
{
}
@@ -316,7 +330,6 @@ QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate())
\sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath()
*/
-
QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate())
{
d_ptr->initFileEngine(file);
@@ -331,7 +344,6 @@ QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate())
\sa isRelative()
*/
-
QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate())
{
d_ptr->initFileEngine(file.fileName());
@@ -349,7 +361,6 @@ QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate())
\sa isRelative()
*/
-
QFileInfo::QFileInfo(const QDir &dir, const QString &file) : d_ptr(new QFileInfoPrivate())
{
d_ptr->initFileEngine(dir.filePath(file));
@@ -358,7 +369,6 @@ QFileInfo::QFileInfo(const QDir &dir, const QString &file) : d_ptr(new QFileInfo
/*!
Constructs a new QFileInfo that is a copy of the given \a fileinfo.
*/
-
QFileInfo::QFileInfo(const QFileInfo &fileinfo) : d_ptr(new QFileInfoPrivate(&fileinfo))
{
@@ -368,7 +378,6 @@ QFileInfo::QFileInfo(const QFileInfo &fileinfo) : d_ptr(new QFileInfoPrivate(&fi
Destroys the QFileInfo and frees its resources.
*/
-
QFileInfo::~QFileInfo()
{
}
@@ -395,19 +404,19 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
Q_D(const QFileInfo);
// ### Qt 5: understand long and short file names on Windows
// ### (GetFullPathName()).
- if(fileinfo.d_func()->data == d->data)
+ if (fileinfo.d_func()->data == d->data)
return true;
- if(!d->data->fileEngine || !fileinfo.d_func()->data->fileEngine)
+ if (!d->data->fileEngine || !fileinfo.d_func()->data->fileEngine)
return false;
- if(d->data->fileEngine->caseSensitive() != fileinfo.d_func()->data->fileEngine->caseSensitive())
+ if (d->data->fileEngine->caseSensitive() != fileinfo.d_func()->data->fileEngine->caseSensitive())
return false;
- if(fileinfo.size() == size()) { //if the size isn't the same...
+ if (fileinfo.size() == size()) { //if the size isn't the same...
QString file1 = canonicalFilePath(),
file2 = fileinfo.canonicalFilePath();
- if(file1.length() == file2.length()) {
- if(!fileinfo.d_func()->data->fileEngine->caseSensitive()) {
- for(int i = 0; i < file1.length(); i++) {
- if(file1.at(i).toLower() != file2.at(i).toLower())
+ if (file1.length() == file2.length()) {
+ if (!fileinfo.d_func()->data->fileEngine->caseSensitive()) {
+ for (int i = 0; i < file1.length(); i++) {
+ if (file1.at(i).toLower() != file2.at(i).toLower())
return false;
}
return true;
@@ -441,7 +450,6 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo)
/*!
Makes a copy of the given \a fileinfo and assigns it to this QFileInfo.
*/
-
QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo)
{
Q_D(QFileInfo);
@@ -464,7 +472,6 @@ QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo)
\sa isRelative(), QDir::setCurrent(), QDir::isRelativePath()
*/
-
void QFileInfo::setFile(const QString &file)
{
*this = QFileInfo(file);
@@ -481,7 +488,6 @@ void QFileInfo::setFile(const QString &file)
\sa isRelative()
*/
-
void QFileInfo::setFile(const QFile &file)
{
*this = QFileInfo(file.fileName());
@@ -498,7 +504,6 @@ void QFileInfo::setFile(const QFile &file)
\sa isRelative()
*/
-
void QFileInfo::setFile(const QDir &dir, const QString &file)
{
*this = QFileInfo(dir.filePath(file));
@@ -528,25 +533,24 @@ void QFileInfo::setFile(const QDir &dir, const QString &file)
QString QFileInfo::absoluteFilePath() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::AbsoluteName);
}
/*!
- Returns the canonical path including the file name, i.e. an absolute
- path without symbolic links or redundant "." or ".." elements.
+ Returns the canonical path including the file name, i.e. an absolute
+ path without symbolic links or redundant "." or ".." elements.
- If the file does not exist, canonicalFilePath() returns an empty
- string.
+ If the file does not exist, canonicalFilePath() returns an empty
+ string.
- \sa filePath(), absoluteFilePath(), dir()
+ \sa filePath(), absoluteFilePath(), dir()
*/
-
QString QFileInfo::canonicalFilePath() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::CanonicalName);
}
@@ -569,7 +573,6 @@ QString QFileInfo::canonicalFilePath() const
\sa absoluteFilePath(), path(), canonicalPath(), fileName(), isRelative()
*/
-
QString QFileInfo::absolutePath() const
{
Q_D(const QFileInfo);
@@ -591,16 +594,14 @@ QString QFileInfo::absolutePath() const
\sa path(), absolutePath()
*/
-
QString QFileInfo::canonicalPath() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::CanonicalPathName);
}
-
/*!
Returns the file's path. This doesn't include the file name.
@@ -610,11 +611,10 @@ QString QFileInfo::canonicalPath() const
\sa filePath(), absolutePath(), canonicalPath(), dir(), fileName(), isRelative()
*/
-
QString QFileInfo::path() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::PathName);
}
@@ -635,16 +635,14 @@ QString QFileInfo::path() const
\sa isAbsolute()
*/
-
bool QFileInfo::isRelative() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return true;
return d->data->fileEngine->isRelativePath();
}
-
/*!
Converts the file's path to an absolute path if it is not already in that form.
Returns true to indicate that the path was converted; otherwise returns false
@@ -652,11 +650,10 @@ bool QFileInfo::isRelative() const
\sa filePath(), isRelative()
*/
-
bool QFileInfo::makeAbsolute()
{
Q_D(QFileInfo);
- if(!d->data->fileEngine || !d->data->fileEngine->isRelativePath())
+ if (!d->data->fileEngine || !d->data->fileEngine->isRelativePath())
return false;
QString absFileName = d->getFileName(QAbstractFileEngine::AbsoluteName);
d->initFileEngine(absFileName);
@@ -669,11 +666,10 @@ bool QFileInfo::makeAbsolute()
\note If the file is a symlink that points to a non existing
file, false is returned.
*/
-
bool QFileInfo::exists() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::ExistsFlag);
}
@@ -685,7 +681,6 @@ bool QFileInfo::exists() const
\note On Windows CE, there might be a delay for the file system driver
to detect changes on the file.
*/
-
void QFileInfo::refresh()
{
Q_D(QFileInfo);
@@ -698,11 +693,10 @@ void QFileInfo::refresh()
\sa absoluteFilePath(), canonicalFilePath(), isRelative()
*/
-
QString QFileInfo::filePath() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::DefaultName);
}
@@ -718,11 +712,10 @@ QString QFileInfo::filePath() const
\sa isRelative(), filePath(), baseName(), extension()
*/
-
QString QFileInfo::fileName() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::BaseName);
}
@@ -739,11 +732,10 @@ QString QFileInfo::fileName() const
\sa isBundle(), filePath(), baseName(), extension()
*/
-
QString QFileInfo::bundleName() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::BundleName);
}
@@ -764,11 +756,10 @@ QString QFileInfo::bundleName() const
\sa fileName(), suffix(), completeSuffix(), completeBaseName()
*/
-
QString QFileInfo::baseName() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::BaseName).section(QLatin1Char('.'), 0, 0);
}
@@ -784,11 +775,10 @@ QString QFileInfo::baseName() const
\sa fileName(), suffix(), completeSuffix(), baseName()
*/
-
QString QFileInfo::completeBaseName() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
QString name = d->getFileName(QAbstractFileEngine::BaseName);
int index = name.lastIndexOf(QLatin1Char('.'));
@@ -806,11 +796,10 @@ QString QFileInfo::completeBaseName() const
\sa fileName(), suffix(), baseName(), completeBaseName()
*/
-
QString QFileInfo::completeSuffix() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
QString fileName = d->getFileName(QAbstractFileEngine::BaseName);
int firstDot = fileName.indexOf(QLatin1Char('.'));
@@ -834,11 +823,10 @@ QString QFileInfo::completeSuffix() const
\sa fileName(), completeSuffix(), baseName(), completeBaseName()
*/
-
QString QFileInfo::suffix() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
QString fileName = d->getFileName(QAbstractFileEngine::BaseName);
int lastDot = fileName.lastIndexOf(QLatin1Char('.'));
@@ -849,24 +837,23 @@ QString QFileInfo::suffix() const
/*!
- Returns the path of the object's parent directory as a QDir object.
+ Returns the path of the object's parent directory as a QDir object.
- \bold{Note:} The QDir returned always corresponds to the object's
- parent directory, even if the QFileInfo represents a directory.
+ \bold{Note:} The QDir returned always corresponds to the object's
+ parent directory, even if the QFileInfo represents a directory.
- For each of the follwing, dir() returns a QDir for
- \c{"~/examples/191697"}.
+ For each of the follwing, dir() returns a QDir for
+ \c{"~/examples/191697"}.
- \snippet doc/src/snippets/fileinfo/main.cpp 0
+ \snippet doc/src/snippets/fileinfo/main.cpp 0
- For each of the follwing, dir() returns a QDir for
- \c{"."}.
+ For each of the follwing, dir() returns a QDir for
+ \c{"."}.
- \snippet doc/src/snippets/fileinfo/main.cpp 1
+ \snippet doc/src/snippets/fileinfo/main.cpp 1
- \sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir()
+ \sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir()
*/
-
QDir QFileInfo::dir() const
{
// ### Qt5: Maybe rename this to parentDirectory(), considering what it actually do?
@@ -878,7 +865,6 @@ QDir QFileInfo::dir() const
\sa dir(), filePath(), fileName(), isRelative()
*/
-
QDir QFileInfo::absoluteDir() const
{
return QDir(absolutePath());
@@ -891,7 +877,7 @@ QDir QFileInfo::absoluteDir() const
*/
QDir QFileInfo::dir(bool absPath) const
{
- if(absPath)
+ if (absPath)
return absoluteDir();
return dir();
}
@@ -902,11 +888,10 @@ QDir QFileInfo::dir(bool absPath) const
\sa isWritable(), isExecutable(), permission()
*/
-
bool QFileInfo::isReadable() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->hasAccess(QFileInfoPrivate::ReadAccess);
}
@@ -916,11 +901,10 @@ bool QFileInfo::isReadable() const
\sa isReadable(), isExecutable(), permission()
*/
-
bool QFileInfo::isWritable() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->hasAccess(QFileInfoPrivate::WriteAccess);
}
@@ -930,11 +914,10 @@ bool QFileInfo::isWritable() const
\sa isReadable(), isWritable(), permission()
*/
-
bool QFileInfo::isExecutable() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->hasAccess(QFileInfoPrivate::ExecuteAccess);
}
@@ -948,7 +931,7 @@ bool QFileInfo::isExecutable() const
bool QFileInfo::isHidden() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::HiddenFlag);
}
@@ -960,11 +943,10 @@ bool QFileInfo::isHidden() const
\sa isDir(), isSymLink(), isBundle()
*/
-
bool QFileInfo::isFile() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::FileType);
}
@@ -975,11 +957,10 @@ bool QFileInfo::isFile() const
\sa isFile(), isSymLink(), isBundle()
*/
-
bool QFileInfo::isDir() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::DirectoryType);
}
@@ -992,11 +973,10 @@ bool QFileInfo::isDir() const
\sa isDir(), isSymLink(), isFile()
*/
-
bool QFileInfo::isBundle() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::BundleType);
}
@@ -1018,21 +998,19 @@ bool QFileInfo::isBundle() const
\sa isFile(), isDir(), symLinkTarget()
*/
-
bool QFileInfo::isSymLink() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::LinkType);
}
/*!
- Returns true if the object points to a directory or to a symbolic
- link to a directory, and that directory is the root directory; otherwise
- returns false.
+ Returns true if the object points to a directory or to a symbolic
+ link to a directory, and that directory is the root directory; otherwise
+ returns false.
*/
-
bool QFileInfo::isRoot() const
{
Q_D(const QFileInfo);
@@ -1064,7 +1042,7 @@ bool QFileInfo::isRoot() const
QString QFileInfo::readLink() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
return d->getFileName(QAbstractFileEngine::LinkName);
}
@@ -1079,13 +1057,12 @@ QString QFileInfo::readLink() const
\sa ownerId(), group(), groupId()
*/
-
QString QFileInfo::owner() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
- return d->data->fileEngine->owner(QAbstractFileEngine::OwnerUser);
+ return d->getFileOwner(QAbstractFileEngine::OwnerUser);
}
/*!
@@ -1096,11 +1073,10 @@ QString QFileInfo::owner() const
\sa owner(), group(), groupId()
*/
-
uint QFileInfo::ownerId() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return 0;
return d->data->fileEngine->ownerId(QAbstractFileEngine::OwnerUser);
}
@@ -1115,13 +1091,12 @@ uint QFileInfo::ownerId() const
\sa groupId(), owner(), ownerId()
*/
-
QString QFileInfo::group() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QLatin1String("");
- return d->data->fileEngine->owner(QAbstractFileEngine::OwnerGroup);
+ return d->getFileOwner(QAbstractFileEngine::OwnerGroup);
}
/*!
@@ -1132,11 +1107,10 @@ QString QFileInfo::group() const
\sa group(), owner(), ownerId()
*/
-
uint QFileInfo::groupId() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return 0;
return d->data->fileEngine->ownerId(QAbstractFileEngine::OwnerGroup);
}
@@ -1154,11 +1128,10 @@ uint QFileInfo::groupId() const
\sa isReadable(), isWritable(), isExecutable()
*/
-
bool QFileInfo::permission(QFile::Permissions permissions) const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return false;
return d->getFileFlags(QAbstractFileEngine::FileFlags((int)permissions)) == (uint)permissions;
}
@@ -1167,11 +1140,10 @@ bool QFileInfo::permission(QFile::Permissions permissions) const
Returns the complete OR-ed together combination of
QFile::Permissions for the file.
*/
-
QFile::Permissions QFileInfo::permissions() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return 0;
return QFile::Permissions(d->getFileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask);
}
@@ -1183,13 +1155,12 @@ QFile::Permissions QFileInfo::permissions() const
\sa exists()
*/
-
qint64 QFileInfo::size() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return 0;
- if(!d->data->getCachedFlag(QFileInfoPrivate::CachedSize)) {
+ if (!d->data->getCachedFlag(QFileInfoPrivate::CachedSize)) {
d->data->setCachedFlag(QFileInfoPrivate::CachedSize);
d->data->fileSize = d->data->fileEngine->size();
}
@@ -1209,11 +1180,10 @@ qint64 QFileInfo::size() const
\sa lastModified() lastRead()
*/
-
QDateTime QFileInfo::created() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QDateTime();
return d->getFileTime(QAbstractFileEngine::CreationTime);
}
@@ -1223,11 +1193,10 @@ QDateTime QFileInfo::created() const
\sa created() lastRead()
*/
-
QDateTime QFileInfo::lastModified() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QDateTime();
return d->getFileTime(QAbstractFileEngine::ModificationTime);
}
@@ -1240,11 +1209,10 @@ QDateTime QFileInfo::lastModified() const
\sa created() lastModified()
*/
-
QDateTime QFileInfo::lastRead() const
{
Q_D(const QFileInfo);
- if(!d->data->fileEngine)
+ if (!d->data->fileEngine)
return QDateTime();
return d->getFileTime(QAbstractFileEngine::AccessTime);
}
@@ -1252,7 +1220,6 @@ QDateTime QFileInfo::lastRead() const
/*! \internal
Detaches all internal data.
*/
-
void QFileInfo::detach()
{
Q_D(QFileInfo);
@@ -1264,7 +1231,6 @@ void QFileInfo::detach()
\sa setCaching(), refresh()
*/
-
bool QFileInfo::caching() const
{
Q_D(const QFileInfo);
@@ -1283,7 +1249,6 @@ bool QFileInfo::caching() const
\sa refresh(), caching()
*/
-
void QFileInfo::setCaching(bool enable)
{
Q_D(QFileInfo);
diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h
index 065f860..d97a0cf 100644
--- a/src/corelib/io/qfileinfo_p.h
+++ b/src/corelib/io/qfileinfo_p.h
@@ -54,6 +54,9 @@
//
#include "qfileinfo.h"
+#include "qabstractfileengine.h"
+#include "qdatetime.h"
+#include "qatomic.h"
QT_BEGIN_NAMESPACE
@@ -75,35 +78,41 @@ public:
uint getFileFlags(QAbstractFileEngine::FileFlags) const;
QDateTime &getFileTime(QAbstractFileEngine::FileTime) const;
QString getFileName(QAbstractFileEngine::FileName) const;
+ QString getFileOwner(QAbstractFileEngine::FileOwner own) const;
enum { CachedFileFlags=0x01, CachedLinkTypeFlag=0x02, CachedBundleTypeFlag=0x04,
CachedMTime=0x10, CachedCTime=0x20, CachedATime=0x40,
- CachedSize =0x08 };
+ CachedSize =0x08, CachedPerms=0x80 };
struct Data {
inline Data()
- : ref(1), fileEngine(0), cache_enabled(1), fileSize(0)
- { clear(); }
+ : ref(1), fileEngine(0),
+ cachedFlags(0), cache_enabled(1), fileFlags(0), fileSize(0)
+ {}
inline Data(const Data &copy)
: ref(1), fileEngine(QAbstractFileEngine::create(copy.fileName)),
- fileName(copy.fileName), cache_enabled(copy.cache_enabled), fileSize(copy.fileSize)
- { clear(); }
+ fileName(copy.fileName),
+ cachedFlags(0), cache_enabled(copy.cache_enabled), fileFlags(0), fileSize(0)
+ {}
inline ~Data() { delete fileEngine; }
inline void clearFlags() {
fileFlags = 0;
cachedFlags = 0;
if (fileEngine)
- (void)fileEngine->fileFlags(QFSFileEngine::Refresh);
+ (void)fileEngine->fileFlags(QAbstractFileEngine::Refresh);
}
inline void clear() {
clearFlags();
for (int i = QAbstractFileEngine::NFileNames - 1 ; i >= 0 ; --i)
fileNames[i].clear();
+ fileOwners[1].clear();
+ fileOwners[0].clear();
}
mutable QAtomicInt ref;
QAbstractFileEngine *fileEngine;
mutable QString fileName;
mutable QString fileNames[QAbstractFileEngine::NFileNames];
+ mutable QString fileOwners[2];
mutable uint cachedFlags : 31;
mutable uint cache_enabled : 1;
diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp
index 451fbd4..7223e49 100644
--- a/src/corelib/io/qfilesystemwatcher.cpp
+++ b/src/corelib/io/qfilesystemwatcher.cpp
@@ -248,7 +248,7 @@ QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine()
eng = QDnotifyFileSystemWatcherEngine::create();
return eng;
#elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC)
-# if 0 && (defined Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
+# if defined(Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
return QFSEventsFileSystemWatcherEngine::create();
else
diff --git a/src/corelib/io/qfilesystemwatcher_dnotify.cpp b/src/corelib/io/qfilesystemwatcher_dnotify.cpp
index 1a218c7..82470c8 100644
--- a/src/corelib/io/qfilesystemwatcher_dnotify.cpp
+++ b/src/corelib/io/qfilesystemwatcher_dnotify.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#include "qplatformdefs.h"
#include "qfilesystemwatcher.h"
#include "qfilesystemwatcher_dnotify_p.h"
@@ -255,16 +256,16 @@ QStringList QDnotifyFileSystemWatcherEngine::addPaths(const QStringList &paths,
if(fd == 0) {
- DIR *d = ::opendir(path.toUtf8().constData());
+ QT_DIR *d = QT_OPENDIR(path.toUtf8().constData());
if(!d) continue; // Could not open directory
- DIR *parent = 0;
+ QT_DIR *parent = 0;
QDir parentDir(path);
if(!parentDir.isRoot()) {
parentDir.cdUp();
- parent = ::opendir(parentDir.path().toUtf8().constData());
+ parent = QT_OPENDIR(parentDir.path().toUtf8().constData());
if(!parent) {
- ::closedir(d);
+ QT_CLOSEDIR(d);
continue;
}
}
@@ -272,8 +273,8 @@ QStringList QDnotifyFileSystemWatcherEngine::addPaths(const QStringList &paths,
fd = qt_safe_dup(::dirfd(d));
int parentFd = parent ? qt_safe_dup(::dirfd(parent)) : 0;
- ::closedir(d);
- if(parent) ::closedir(parent);
+ QT_CLOSEDIR(d);
+ if(parent) QT_CLOSEDIR(parent);
Q_ASSERT(fd);
if(::fcntl(fd, F_SETSIG, SIGIO) ||
diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.cpp b/src/corelib/io/qfilesystemwatcher_fsevents.cpp
index 046377e..54ae24e 100644
--- a/src/corelib/io/qfilesystemwatcher_fsevents.cpp
+++ b/src/corelib/io/qfilesystemwatcher_fsevents.cpp
@@ -94,7 +94,7 @@ static void addPathToHash(PathHash &pathHash, const QString &key, const QFileInf
{
PathInfoList &list = pathHash[key];
list.push_back(PathInfo(path,
- fileInfo.absoluteFilePath().normalized(QString::NormalizationForm_D).toUtf8()));
+ fileInfo.canonicalFilePath().normalized(QString::NormalizationForm_D).toUtf8()));
pathHash.insert(key, list);
}
@@ -206,7 +206,7 @@ QStringList QFSEventsFileSystemWatcherEngine::addPaths(const QStringList &paths,
} else {
directories->append(path);
// Full file path for dirs.
- QCFString cfpath(createFSStreamPath(fileInfo.absoluteFilePath()));
+ QCFString cfpath(createFSStreamPath(fileInfo.canonicalFilePath()));
addPathToHash(dirPathInfoHash, cfpath, fileInfo, path);
CFArrayAppendValue(tmpArray, cfpath);
}
@@ -216,7 +216,7 @@ QStringList QFSEventsFileSystemWatcherEngine::addPaths(const QStringList &paths,
continue;
} else {
// Just the absolute path (minus it's filename) for files.
- QCFString cfpath(createFSStreamPath(fileInfo.absolutePath()));
+ QCFString cfpath(createFSStreamPath(fileInfo.canonicalPath()));
files->append(path);
addPathToHash(filePathInfoHash, cfpath, fileInfo, path);
CFArrayAppendValue(tmpArray, cfpath);
@@ -293,7 +293,7 @@ QStringList QFSEventsFileSystemWatcherEngine::removePaths(const QStringList &pat
itemCount = CFArrayGetCount(tmpArray);
const QString &path = paths.at(i);
QFileInfo fi(path);
- QCFString cfpath(createFSStreamPath(fi.absolutePath()));
+ QCFString cfpath(createFSStreamPath(fi.canonicalPath()));
CFIndex index = CFArrayGetFirstIndexOfValue(tmpArray, CFRangeMake(0, itemCount), cfpath);
if (index != -1) {
@@ -302,7 +302,7 @@ QStringList QFSEventsFileSystemWatcherEngine::removePaths(const QStringList &pat
removePathFromHash(filePathInfoHash, cfpath, path);
} else {
// Could be a directory we are watching instead.
- QCFString cfdirpath(createFSStreamPath(fi.absoluteFilePath()));
+ QCFString cfdirpath(createFSStreamPath(fi.canonicalFilePath()));
index = CFArrayGetFirstIndexOfValue(tmpArray, CFRangeMake(0, itemCount), cfdirpath);
if (index != -1) {
CFArrayRemoveValueAtIndex(tmpArray, index);
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index c842e49..1672dfc 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -56,6 +56,9 @@
#endif
#include <stdio.h>
#include <stdlib.h>
+#if defined(Q_OS_MAC)
+# include <private/qcore_mac_p.h>
+#endif
QT_BEGIN_NAMESPACE
@@ -143,9 +146,27 @@ QString QFSFileEnginePrivate::canonicalized(const QString &path)
if (path.size() == 1 && path.at(0) == QLatin1Char('/'))
return path;
#endif
- // Mac OS X 10.5.x doesn't support the realpath(X,0) extenstion we use here.
-#if defined(Q_OS_LINUX) || defined(Q_OS_SYMBIAN)
- char *ret = realpath(path.toLocal8Bit().constData(), (char*)0);
+#if defined(Q_OS_LINUX) || defined(Q_OS_SYMBIAN) || defined(Q_OS_MAC)
+ 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);
diff --git a/src/corelib/io/qfsfileengine_iterator_unix.cpp b/src/corelib/io/qfsfileengine_iterator_unix.cpp
index b68b1a1..bfdb03e 100644
--- a/src/corelib/io/qfsfileengine_iterator_unix.cpp
+++ b/src/corelib/io/qfsfileengine_iterator_unix.cpp
@@ -58,13 +58,13 @@ public:
#endif
{}
- DIR *dir;
- dirent *dirEntry;
+ QT_DIR *dir;
+ QT_DIRENT *dirEntry;
bool done;
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN)
// for readdir_r
- dirent *mt_file;
+ QT_DIRENT *mt_file;
#endif
};
@@ -76,14 +76,14 @@ void QFSFileEngineIterator::advance()
return;
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN)
- if (::readdir_r(platform->dir, platform->mt_file, &platform->dirEntry) != 0)
+ if (QT_READDIR_R(platform->dir, platform->mt_file, &platform->dirEntry) != 0)
platform->done = true;
#else
// ### add local lock to prevent breaking reentrancy
- platform->dirEntry = ::readdir(platform->dir);
+ platform->dirEntry = QT_READDIR(platform->dir);
#endif // _POSIX_THREAD_SAFE_FUNCTIONS
if (!platform->dirEntry) {
- ::closedir(platform->dir);
+ QT_CLOSEDIR(platform->dir);
platform->dir = 0;
platform->done = true;
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN)
@@ -101,7 +101,7 @@ void QFSFileEngineIterator::newPlatformSpecifics()
void QFSFileEngineIterator::deletePlatformSpecifics()
{
if (platform->dir) {
- ::closedir(platform->dir);
+ QT_CLOSEDIR(platform->dir);
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN)
delete [] platform->mt_file;
platform->mt_file = 0;
@@ -115,18 +115,18 @@ bool QFSFileEngineIterator::hasNext() const
{
if (!platform->done && !platform->dir) {
QFSFileEngineIterator *that = const_cast<QFSFileEngineIterator *>(this);
- if ((that->platform->dir = ::opendir(QFile::encodeName(path()).data())) == 0) {
+ if ((that->platform->dir = QT_OPENDIR(QFile::encodeName(path()).data())) == 0) {
that->platform->done = true;
} else {
// ### Race condition; we should use fpathconf and dirfd().
long maxPathName = ::pathconf(QFile::encodeName(path()).data(), _PC_NAME_MAX);
if ((int) maxPathName == -1)
maxPathName = FILENAME_MAX;
- maxPathName += sizeof(dirent) + 1;
+ maxPathName += sizeof(QT_DIRENT) + 1;
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN)
if (that->platform->mt_file)
delete [] that->platform->mt_file;
- that->platform->mt_file = (dirent *)new char[maxPathName];
+ that->platform->mt_file = (QT_DIRENT *)new char[maxPathName];
#endif
that->advance();
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index ca01eb2..eb99f27 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -177,7 +177,7 @@ void QFSFileEnginePrivate::resolveLibs()
triedResolve = true;
#if !defined(Q_OS_WINCE)
- HINSTANCE advapiHnd = LoadLibraryW(L"advapi32");
+ HINSTANCE advapiHnd = LoadLibrary(L"advapi32");
if (advapiHnd) {
ptrGetNamedSecurityInfoW = (PtrGetNamedSecurityInfoW)GetProcAddress(advapiHnd, "GetNamedSecurityInfoW");
ptrLookupAccountSidW = (PtrLookupAccountSidW)GetProcAddress(advapiHnd, "LookupAccountSidW");
@@ -209,7 +209,7 @@ void QFSFileEnginePrivate::resolveLibs()
ptrFreeSid(pWorld);
}
}
- HINSTANCE userenvHnd = LoadLibraryW(L"userenv");
+ HINSTANCE userenvHnd = LoadLibrary(L"userenv");
if (userenvHnd)
ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW");
#endif
@@ -217,7 +217,6 @@ void QFSFileEnginePrivate::resolveLibs()
}
#endif // QT_NO_LIBRARY
-// UNC functions NT
typedef DWORD (WINAPI *PtrNetShareEnum)(LPWSTR, DWORD, LPBYTE*, DWORD, LPDWORD, LPDWORD, LPDWORD);
static PtrNetShareEnum ptrNetShareEnum = 0;
typedef DWORD (WINAPI *PtrNetApiBufferFree)(LPVOID);
@@ -241,7 +240,7 @@ bool QFSFileEnginePrivate::resolveUNCLibs()
#endif
triedResolve = true;
#if !defined(Q_OS_WINCE)
- HINSTANCE hLib = LoadLibraryW(L"Netapi32");
+ HINSTANCE hLib = LoadLibrary(L"netapi32");
if (hLib) {
ptrNetShareEnum = (PtrNetShareEnum)GetProcAddress(hLib, "NetShareEnum");
if (ptrNetShareEnum)
@@ -1038,11 +1037,11 @@ QString QFSFileEngine::homePath()
if (ok) {
DWORD dwBufferSize = 0;
// First call, to determine size of the strings (with '\0').
- ok = ::ptrGetUserProfileDirectoryW(token, NULL, &dwBufferSize);
+ ok = ptrGetUserProfileDirectoryW(token, NULL, &dwBufferSize);
if (!ok && dwBufferSize != 0) { // We got the required buffer size
wchar_t *userDirectory = new wchar_t[dwBufferSize];
// Second call, now we can fill the allocated buffer.
- ok = ::ptrGetUserProfileDirectoryW(token, userDirectory, &dwBufferSize);
+ ok = ptrGetUserProfileDirectoryW(token, userDirectory, &dwBufferSize);
if (ok)
ret = QString::fromWCharArray(userDirectory);
@@ -1414,7 +1413,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
QAbstractFileEngine::FileFlags ret = 0;
#if !defined(QT_NO_LIBRARY)
- if((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
+ if((qt_ntfs_permission_lookup > 0) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)) {
resolveLibs();
if(ptrGetNamedSecurityInfoW && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW) {
enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 };
@@ -1717,8 +1716,7 @@ QString QFSFileEngine::owner(FileOwner own) const
QString name;
#if !defined(QT_NO_LIBRARY)
Q_D(const QFSFileEngine);
-
- if ((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
+ if((qt_ntfs_permission_lookup > 0) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)) {
QFSFileEnginePrivate::resolveLibs();
if (ptrGetNamedSecurityInfoW && ptrLookupAccountSidW) {
PSID pOwner = 0;
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index 0aa534a..906979c 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -46,6 +46,7 @@
#include <QtCore/qobjectdefs.h>
#include <QtCore/qpair.h>
#include <QtCore/qstring.h>
+#include <QtCore/qhash.h>
QT_BEGIN_HEADER
@@ -75,6 +76,7 @@ public:
RemovePath = 0x20,
RemoveQuery = 0x40,
RemoveFragment = 0x80,
+ // 0x100: private: normalized
StripTrailingSlash = 0x10000
};
@@ -268,6 +270,11 @@ public:
inline DataPtr &data_ptr() { return d; }
};
+inline uint qHash(const QUrl &uri)
+{
+ return qHash(uri.toEncoded(QUrl::FormattingOption(0x100)));
+}
+
Q_DECLARE_TYPEINFO(QUrl, Q_MOVABLE_TYPE);
Q_DECLARE_SHARED(QUrl)
Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions)