summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-10-24 12:48:39 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-10-24 12:48:42 +0200
commit840f6a40e6218992b5b9d451ee3c0886a4846c89 (patch)
tree2b808decc7adf5218b810d2de6b45c5a8b4cfc42 /src/corelib/io
parent109bf980b37fed405c6c1eb14cb9c83ff897e389 (diff)
parent2e3870fe37d36ccf4bd84eb90e1d5e08ad00c1bc (diff)
Merge remote-tracking branch 'origin/stable' into dev
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfileinfo.cpp5
-rw-r--r--src/corelib/io/qfileinfo_p.h14
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp14
-rw-r--r--src/corelib/io/qiodevice.cpp8
-rw-r--r--src/corelib/io/qlockfile_unix.cpp17
-rw-r--r--src/corelib/io/qloggingcategory.cpp87
-rw-r--r--src/corelib/io/qloggingcategory.h6
-rw-r--r--src/corelib/io/qurl.cpp17
-rw-r--r--src/corelib/io/qurlrecode.cpp5
9 files changed, 117 insertions, 56 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index 90122a9f0d..897af352c9 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -675,6 +675,8 @@ bool QFileInfo::exists() const
}
/*!
+ \since 5.2
+
Returns \c true if the \a file exists; otherwise returns \c false.
\note If \a file is a symlink that points to a non-existing
@@ -691,7 +693,8 @@ bool QFileInfo::exists(const QString &file)
QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data);
// Expensive fallback to non-QFileSystemEngine implementation
if (engine)
- return QFileInfo(file).exists();
+ return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists();
+
QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
return data.exists();
}
diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h
index 442e6b5ef0..47359a55ce 100644
--- a/src/corelib/io/qfileinfo_p.h
+++ b/src/corelib/io/qfileinfo_p.h
@@ -120,6 +120,20 @@ public:
metaData = QFileSystemMetaData();
}
+ inline QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, QAbstractFileEngine *engine)
+ : fileEntry(file),
+ metaData(data),
+ fileEngine(engine),
+ cachedFlags(0),
+#ifndef QT_NO_FSFILEENGINE
+ isDefaultConstructed(false),
+#else
+ isDefaultConstructed(!fileEngine),
+#endif
+ cache_enabled(true), fileFlags(0), fileSize(0)
+ {
+ }
+
inline void clearFlags() const {
fileFlags = 0;
cachedFlags = 0;
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
index 105c8d34dd..77304b2cb9 100644
--- a/src/corelib/io/qfilesystemengine_win.cpp
+++ b/src/corelib/io/qfilesystemengine_win.cpp
@@ -1038,8 +1038,10 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
return data.hasFlags(what);
}
-static inline bool mkDir(const QString &path)
+static inline bool mkDir(const QString &path, DWORD *lastError = 0)
{
+ if (lastError)
+ *lastError = 0;
#if defined(Q_OS_WINCE)
// Unfortunately CreateDirectory returns true for paths longer than
// 256, but does not create a directory. It starts to fail, when
@@ -1059,7 +1061,11 @@ static inline bool mkDir(const QString &path)
if (platformId == 1 && QFSFileEnginePrivate::longFileName(path).size() > 256)
return false;
#endif
- return ::CreateDirectory((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16(), 0);
+ const QString longPath = QFSFileEnginePrivate::longFileName(path);
+ const bool result = ::CreateDirectory((wchar_t*)longPath.utf16(), 0);
+ if (lastError) // Capture lastError before any QString is freed since custom allocators might change it.
+ *lastError = GetLastError();
+ return result;
}
static inline bool rmDir(const QString &path)
@@ -1131,9 +1137,9 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea
slash = dirName.length();
}
if (slash) {
+ DWORD lastError;
QString chunk = dirName.left(slash);
- if (!mkDir(chunk)) {
- const DWORD lastError = GetLastError();
+ if (!mkDir(chunk, &lastError)) {
if (lastError == ERROR_ALREADY_EXISTS || lastError == ERROR_ACCESS_DENIED) {
bool existed = false;
if (isDirPath(chunk, &existed) && existed)
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 8fb80123fa..a81b8580c4 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -99,8 +99,10 @@ void debugBinaryString(const char *data, qint64 maxlen)
#define CHECK_WRITABLE(function, returnType) \
do { \
if ((d->openMode & WriteOnly) == 0) { \
- if (d->openMode == NotOpen) \
+ if (d->openMode == NotOpen) { \
+ qWarning("QIODevice::"#function": device not open"); \
return returnType; \
+ } \
qWarning("QIODevice::"#function": ReadOnly device"); \
return returnType; \
} \
@@ -109,8 +111,10 @@ void debugBinaryString(const char *data, qint64 maxlen)
#define CHECK_READABLE(function, returnType) \
do { \
if ((d->openMode & ReadOnly) == 0) { \
- if (d->openMode == NotOpen) \
+ if (d->openMode == NotOpen) { \
+ qWarning("QIODevice::"#function": device not open"); \
return returnType; \
+ } \
qWarning("QIODevice::"#function": WriteOnly device"); \
return returnType; \
} \
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index 1676b71133..dc8817706c 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -140,6 +140,13 @@ static bool setNativeLocks(int fd)
QLockFile::LockError QLockFilePrivate::tryLock_sys()
{
+ // Assemble data, to write in a single call to write
+ // (otherwise we'd have to check every write call)
+ // Use operator% from the fast builder to avoid multiple memory allocations.
+ QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) % '\n'
+ % qAppName().toUtf8() % '\n'
+ % localHostName().toUtf8() % '\n';
+
const QByteArray lockFileName = QFile::encodeName(fileName);
const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
@@ -160,16 +167,6 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys()
// We hold the lock, continue.
fileHandle = fd;
- // Assemble data, to write in a single call to write
- // (otherwise we'd have to check every write call)
- QByteArray fileData;
- fileData += QByteArray::number(QCoreApplication::applicationPid());
- fileData += '\n';
- fileData += qAppName().toUtf8();
- fileData += '\n';
- fileData += localHostName().toUtf8();
- fileData += '\n';
-
QLockFile::LockError error = QLockFile::NoError;
if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size())
error = QLockFile::UnknownError; // partition full
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 6c5df1e8e7..8d337ec630 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -71,30 +71,36 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,
\section1 Checking category configuration
- QLoggingCategory provides a generic \l isEnabled() and message
- type dependent \l isDebugEnabled(), \l isWarningEnabled(),
- \l isCriticalEnabled() and \l isTraceEnabled()
- methods for checking whether the current category is enabled.
+ QLoggingCategory provides \l isDebugEnabled(), \l isWarningEnabled(),
+ \l isCriticalEnabled(), \l isTraceEnabled(), as well as \l isEnabled()
+ to check whether messages for the given message type should be logged.
\note The qCDebug(), qCWarning(), qCCritical(), qCTrace() and
qCTraceGuard() macros prevent arguments from being evaluated if the
respective message types are not enabled for the category, so explicit
checking is not needed:
- \snippet qloggingcategory/main.cpp 3
+ \snippet qloggingcategory/main.cpp 4
- \section1 Default configuration
+ \section1 Default category configuration
In the default configuration \l isWarningEnabled() and \l isCriticalEnabled()
- will return \c true. By default, \l isDebugEnabled() will return \c true only
+ will return \c true. \l isDebugEnabled() will return \c true only
for the \c "default" category.
- \section1 Changing configuration
+ \section1 Changing the configuration of a category
+
+ Use either \l setFilterRules() or \l installFilter() to
+ configure categories, for example
+
+ \snippet qloggingcategory/main.cpp 2
+
+ \section1 Printing the category
+
+ Use the \c %{category} place holder to print the category in the default
+ message handler:
- The default configuration can be changed by calling \l setEnabled(). However,
- this only affects the current category object, not e.g. another object for the
- same category name. Use either \l setFilterRules() or \l installFilter() to
- configure categories globally.
+ \snippet qloggingcategory/main.cpp 3
*/
typedef QVector<QTracer *> Tracers;
@@ -117,7 +123,10 @@ QLoggingCategory::QLoggingCategory(const char *category)
enabledDebug(false),
enabledWarning(true),
enabledCritical(true),
- enabledTrace(false)
+ enabledTrace(false),
+ placeholder1(false),
+ placeholder2(false),
+ placeholder3(false)
{
bool isDefaultCategory
= (category == 0) || (strcmp(category, qtDefaultCategoryName) == 0);
@@ -215,14 +224,12 @@ bool QLoggingCategory::isEnabled(QtMsgType msgtype) const
/*!
Changes the message type \a type for the category to \a enable.
- Changes only affect the current QLoggingCategory object, and won't
- change e.g. the settings of another objects for the same category name.
+ \note Changes only affect the current QLoggingCategory object, and won't
+ change the settings of other objects for the same category name.
+ Use either \l setFilterRules() or \l installFilter() to change the
+ configuration globally.
\note \c QtFatalMsg cannot be changed. It will always return \c true.
-
- Example:
-
- \snippet qtracer/ftracer.cpp 5
*/
void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
{
@@ -244,12 +251,19 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
*/
/*!
- Returns the category \c "default" that is used e.g. by qDebug(), qWarning(),
- qCritical(), qFatal().
+ Returns a pointer to the global category \c "default" that
+ is used e.g. by qDebug(), qWarning(), qCritical(), qFatal().
+
+ \note The returned pointer may be null during destruction of
+ static objects.
+
+ \note Ownership of the category is not transferred, do not
+ \c delete the returned pointer.
+
*/
-QLoggingCategory &QLoggingCategory::defaultCategory()
+QLoggingCategory *QLoggingCategory::defaultCategory()
{
- return *qtDefaultCategory();
+ return qtDefaultCategory();
}
/*!
@@ -272,6 +286,12 @@ QLoggingCategory &QLoggingCategory::defaultCategory()
filter is free to change the respective category configuration with
\l setEnabled().
+ The filter might be called concurrently from different threads, and
+ therefore has to be reentrant.
+
+ Example:
+ \snippet qloggingcategory/main.cpp 21
+
An alternative way of configuring the default filter is via
\l setFilterRules().
*/
@@ -281,7 +301,6 @@ QLoggingCategory::installFilter(QLoggingCategory::CategoryFilter filter)
return QLoggingRegistry::instance()->installFilter(filter);
}
-
/*!
Configures which categories and message types should be enabled through a
a set of \a rules.
@@ -296,8 +315,13 @@ QLoggingCategory::installFilter(QLoggingCategory::CategoryFilter filter)
wildcard symbol at the start and/or the end. The optional \c <type> must
be either \c debug, \c warning, \c critical, or \c trace.
- The rules might be ignored if a custom category filter is installed with
- \l installFilter().
+ Example:
+
+ \snippet qloggingcategory/main.cpp 2
+
+ \note The rules might be ignored if a custom category filter is installed
+ with \l installFilter().
+
*/
void QLoggingCategory::setFilterRules(const QString &rules)
{
@@ -380,7 +404,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
The macro expands to code that checks whether
\l QLoggingCategory::isTraceEnabled() evaluates to \c true.
- If so, the stream arguments are processed and sent to the tracers
+ If so, the stream arguments are processed and sent to the \l QTracer objects
registered with the category.
\note Arguments are not processed if trace output for the category is not
@@ -390,7 +414,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\snippet qtracer/ftracer.cpp 6
- \sa qCTraceGuard()
+ \sa qCTraceGuard() QTraceGuard
*/
/*!
@@ -402,11 +426,12 @@ void QLoggingCategory::setFilterRules(const QString &rules)
storage. The guard constructor checks whether
\l QLoggingCategory::isTraceEnabled() evaluates to \c true.
If so, the stream arguments are processed and the \c{start()}
- functions of the tracers registered with the \a category are called.
+ functions of the \l QTracer objects registered with the \a category are
+ called.
The guard destructor also checks whether the category is enabled for
tracing and if so, the \c{end()}
- functions of the tracers registered with the \a category are called.
+ functions of the \l QTracer objects registered with the \a category are called.
\note Arguments are always processed, even if trace output for the
category is disabled. They will, however, in that case not be passed
@@ -416,7 +441,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\snippet qtracer/ftracer.cpp 4
- \sa qCTrace()
+ \sa qCTrace() QTracer
*/
/*!
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h
index 35da04c8f2..7a119f4937 100644
--- a/src/corelib/io/qloggingcategory.h
+++ b/src/corelib/io/qloggingcategory.h
@@ -72,7 +72,7 @@ public:
// allows usage of both factory method and variable in qCX macros
QLoggingCategory &operator()() { return *this; }
- static QLoggingCategory &defaultCategory();
+ static QLoggingCategory *defaultCategory();
typedef void (*CategoryFilter)(QLoggingCategory*);
static CategoryFilter installFilter(CategoryFilter);
@@ -92,6 +92,10 @@ private:
bool enabledWarning;
bool enabledCritical;
bool enabledTrace;
+ // reserve space for future use
+ bool placeholder1;
+ bool placeholder2;
+ bool placeholder3;
};
class Q_CORE_EXPORT QTracer
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 6b7c5bde2d..fe5faa2be7 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -1840,12 +1840,21 @@ void QUrl::setUrl(const QString &url, ParsingMode parsingMode)
input. It must also start with an ASCII letter.
The scheme describes the type (or protocol) of the URL. It's
- represented by one or more ASCII characters at the start the URL,
- and is followed by a ':'. The following example shows a URL where
- the scheme is "ftp":
+ represented by one or more ASCII characters at the start the URL.
+
+ A scheme is strictly \l {http://www.ietf.org/rfc/rfc3986.txt} {RFC 3986}-compliant:
+ \tt {scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )}
+
+ The following example shows a URL where the scheme is "ftp":
\image qurl-authority2.png
+ To set the scheme, the following call is used:
+ \code
+ QUrl url;
+ url.setScheme("ftp");
+ \endcode
+
The scheme can also be empty, in which case the URL is interpreted
as relative.
@@ -3327,7 +3336,7 @@ QString QUrl::fromPercentEncoding(const QByteArray &input)
them to \a include.
Unreserved is defined as:
- ALPHA / DIGIT / "-" / "." / "_" / "~"
+ \tt {ALPHA / DIGIT / "-" / "." / "_" / "~"}
\snippet code/src_corelib_io_qurl.cpp 6
*/
diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp
index 7e77b9c251..80fc0319fe 100644
--- a/src/corelib/io/qurlrecode.cpp
+++ b/src/corelib/io/qurlrecode.cpp
@@ -304,7 +304,7 @@ static bool encodedUtf8ToUtf16(QString &result, ushort *&output, const ushort *b
// we've decoded something; safety-check it
if (uc < min_uc)
return false;
- if (QChar::isSurrogate(uc) || QChar::isNonCharacter(uc) || uc > QChar::LastValidCodePoint)
+ if (QChar::isSurrogate(uc) || uc > QChar::LastValidCodePoint)
return false;
if (!QChar::requiresSurrogates(uc)) {
@@ -410,10 +410,9 @@ static int recode(QString &result, const ushort *begin, const ushort *end, QUrl:
const ushort *input = begin;
ushort *output = 0;
+ EncodingAction action = EncodeCharacter;
for ( ; input != end; ++input) {
ushort c;
- EncodingAction action;
-
// try a run where no change is necessary
for ( ; input != end; ++input) {
c = *input;