summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-28 09:23:03 +0200
committerLiang Qi <liang.qi@qt.io>2017-03-28 09:28:31 +0200
commitb48a13fd6843e12b5725aa3ff0d010007e7c43b4 (patch)
tree316cfe36fc67906efcd92ff806c7c0da56ed4f8e /src/corelib/io
parent3398d9d40cb0dae2dc2a1a4f7dc3b4b9cceae903 (diff)
parent15fe60cfdada84ea519f08e905d59cc3fb6d20cd (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: examples/examples.pro tests/auto/corelib/tools/qchar/tst_qchar.cpp tests/auto/other/qaccessibility/accessiblewidgets.h Change-Id: I426696c40ab57d14dc295b8103152cede79f244c
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdir.cpp47
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp15
-rw-r--r--src/corelib/io/qlockfile.cpp3
-rw-r--r--src/corelib/io/qlockfile_unix.cpp2
-rw-r--r--src/corelib/io/qlockfile_win.cpp2
-rw-r--r--src/corelib/io/qstandardpaths_mac.mm5
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp2
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp2
-rw-r--r--src/corelib/io/qurl.cpp11
9 files changed, 56 insertions, 33 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index bfb91c131f..6d144cb65d 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -2105,11 +2105,11 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all
return name;
int i = len - 1;
- QVarLengthArray<QChar> outVector(len);
+ QVarLengthArray<ushort> outVector(len);
int used = len;
- QChar *out = outVector.data();
- const QChar *p = name.unicode();
- const QChar *prefix = p;
+ ushort *out = outVector.data();
+ const ushort *p = name.utf16();
+ const ushort *prefix = p;
int up = 0;
const int prefixLength = rootLength(name, allowUncPaths);
@@ -2117,39 +2117,39 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all
i -= prefixLength;
// replicate trailing slash (i > 0 checks for emptiness of input string p)
- if (i > 0 && p[i].unicode() == '/') {
- out[--used].unicode() = '/';
+ if (i > 0 && p[i] == '/') {
+ out[--used] = '/';
--i;
}
while (i >= 0) {
// remove trailing slashes
- if (p[i].unicode() == '/') {
+ if (p[i] == '/') {
--i;
continue;
}
// remove current directory
- if (p[i].unicode() == '.' && (i == 0 || p[i-1].unicode() == '/')) {
+ if (p[i] == '.' && (i == 0 || p[i-1] == '/')) {
--i;
continue;
}
// detect up dir
- if (i >= 1 && p[i].unicode() == '.' && p[i-1].unicode() == '.'
- && (i == 1 || (i >= 2 && p[i-2].unicode() == '/'))) {
+ if (i >= 1 && p[i] == '.' && p[i-1] == '.'
+ && (i == 1 || (i >= 2 && p[i-2] == '/'))) {
++up;
i -= 2;
continue;
}
// prepend a slash before copying when not empty
- if (!up && used != len && out[used].unicode() != '/')
- out[--used] = QLatin1Char('/');
+ if (!up && used != len && out[used] != '/')
+ out[--used] = '/';
// skip or copy
while (i >= 0) {
- if (p[i].unicode() == '/') { // do not copy slashes
+ if (p[i] == '/') { // do not copy slashes
--i;
break;
}
@@ -2171,17 +2171,17 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all
// add remaining '..'
while (up) {
- if (used != len && out[used].unicode() != '/') // is not empty and there isn't already a '/'
- out[--used] = QLatin1Char('/');
- out[--used] = QLatin1Char('.');
- out[--used] = QLatin1Char('.');
+ if (used != len && out[used] != '/') // is not empty and there isn't already a '/'
+ out[--used] = '/';
+ out[--used] = '.';
+ out[--used] = '.';
--up;
}
bool isEmpty = used == len;
if (prefixLength) {
- if (!isEmpty && out[used].unicode() == '/') {
+ if (!isEmpty && out[used] == '/') {
// Eventhough there is a prefix the out string is a slash. This happens, if the input
// string only consists of a prefix followed by one or more slashes. Just skip the slash.
++used;
@@ -2192,18 +2192,19 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all
if (isEmpty) {
// After resolving the input path, the resulting string is empty (e.g. "foo/.."). Return
// a dot in that case.
- out[--used] = QLatin1Char('.');
- } else if (out[used].unicode() == '/') {
+ out[--used] = '.';
+ } else if (out[used] == '/') {
// After parsing the input string, out only contains a slash. That happens whenever all
// parts are resolved and there is a trailing slash ("./" or "foo/../" for example).
// Prepend a dot to have the correct return value.
- out[--used] = QLatin1Char('.');
+ out[--used] = '.';
}
}
// If path was not modified return the original value
- QString ret = (used == 0 ? name : QString(out + used, len - used));
- return ret;
+ if (used == 0)
+ return name;
+ return QString::fromUtf16(out + used, len - used);
}
static QString qt_cleanPath(const QString &path, bool *ok)
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index ff77278dc1..4be4e893b3 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -688,6 +688,19 @@ QDateTime QFSFileEngine::fileTime(FileTime time) const
uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
{
+#if (defined(Q_OS_LINUX) || defined(Q_OS_ANDROID)) && Q_PROCESSOR_WORDSIZE == 4
+ // The Linux mmap2 system call on 32-bit takes a page-shifted 32-bit
+ // integer so the maximum offset is 1 << (32+12) (the shift is always 12,
+ // regardless of the actual page size). Unfortunately, the mmap64()
+ // function is known to be broken in all Linux libcs (glibc, uclibc, musl
+ // and Bionic): all of them do the right shift, but don't confirm that the
+ // result fits into the 32-bit parameter to the kernel.
+
+ static qint64 MaxFileOffset = (Q_INT64_C(1) << (32+12)) - 1;
+#else
+ static qint64 MaxFileOffset = std::numeric_limits<QT_OFF_T>::max();
+#endif
+
Q_Q(QFSFileEngine);
Q_UNUSED(flags);
if (openMode == QIODevice::NotOpen) {
@@ -695,7 +708,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
return 0;
}
- if (offset < 0 || offset != qint64(QT_OFF_T(offset))
+ if (offset < 0 || offset > MaxFileOffset
|| size < 0 || quint64(size) > quint64(size_t(-1))) {
q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL)));
return 0;
diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp
index cb1ff93ad3..48317d07e0 100644
--- a/src/corelib/io/qlockfile.cpp
+++ b/src/corelib/io/qlockfile.cpp
@@ -44,6 +44,7 @@
#include <QtCore/qthread.h>
#include <QtCore/qdeadlinetimer.h>
#include <QtCore/qdatetime.h>
+#include <QtCore/qfileinfo.h>
QT_BEGIN_NAMESPACE
@@ -226,6 +227,8 @@ bool QLockFile::tryLock(int timeout)
return false;
case LockFailedError:
if (!d->isLocked && d->isApparentlyStale()) {
+ if (Q_UNLIKELY(QFileInfo(d->fileName).lastModified() > QDateTime::currentDateTime()))
+ qInfo("QLockFile: Lock file '%ls' has a modification time in the future", qUtf16Printable(d->fileName));
// Stale lock from another thread/process
// Ensure two processes don't remove it at the same time
QLockFile rmlock(d->fileName + QLatin1String(".rmlock"));
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index 3a80014c00..5a02741727 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -247,7 +247,7 @@ bool QLockFilePrivate::isApparentlyStale() const
}
}
const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());
- return staleLockTime > 0 && age > staleLockTime;
+ return staleLockTime > 0 && qAbs(age) > staleLockTime;
}
QString QLockFilePrivate::processNameByPid(qint64 pid)
diff --git a/src/corelib/io/qlockfile_win.cpp b/src/corelib/io/qlockfile_win.cpp
index baaff8da17..4b43181686 100644
--- a/src/corelib/io/qlockfile_win.cpp
+++ b/src/corelib/io/qlockfile_win.cpp
@@ -160,7 +160,7 @@ bool QLockFilePrivate::isApparentlyStale() const
Q_UNUSED(appname);
#endif // Q_OS_WINRT
const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());
- return staleLockTime > 0 && age > staleLockTime;
+ return staleLockTime > 0 && qAbs(age) > staleLockTime;
}
QString QLockFilePrivate::processNameByPid(qint64 pid)
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm
index a293d4862f..e25339a7d1 100644
--- a/src/corelib/io/qstandardpaths_mac.mm
+++ b/src/corelib/io/qstandardpaths_mac.mm
@@ -204,13 +204,14 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
CFBundleRef mainBundle = CFBundleGetMainBundle();
if (mainBundle) {
CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);
- CFStringRef cfBundlePath = CFURLCopyPath(bundleUrl);
+ CFStringRef cfBundlePath = CFURLCopyFileSystemPath(bundleUrl, kCFURLPOSIXPathStyle);
QString bundlePath = QString::fromCFString(cfBundlePath);
CFRelease(cfBundlePath);
CFRelease(bundleUrl);
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(mainBundle);
- CFStringRef cfResourcesPath = CFURLCopyPath(resourcesUrl);
+ CFStringRef cfResourcesPath = CFURLCopyFileSystemPath(resourcesUrl,
+ kCFURLPOSIXPathStyle);
QString resourcesPath = QString::fromCFString(cfResourcesPath);
CFRelease(cfResourcesPath);
CFRelease(resourcesUrl);
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 7974dc8cca..f0ff46fe7f 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -117,7 +117,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
}
case RuntimeLocation:
{
- const uid_t myUid = geteuid();
+ const uint myUid = uint(geteuid());
// http://standards.freedesktop.org/basedir-spec/latest/
QFileInfo fileInfo;
QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index fcc7b8ca50..b9c9883609 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -503,6 +503,8 @@ static QByteArray extractSubvolume(const QStorageIterator &it)
// if we didn't find the subvolume name, return the subvolume ID
return id;
}
+#else
+ Q_UNUSED(it);
#endif
return QByteArray();
}
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 18ad59f1cb..b5772b5ce2 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -4169,12 +4169,15 @@ QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirecto
return url;
}
+ const QFileInfo fileInfo(QDir(workingDirectory), userInput);
+ if (fileInfo.exists()) {
+ return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
+ }
+
QUrl url = QUrl(userInput, QUrl::TolerantMode);
// Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes)
- if (url.isRelative() && !QDir::isAbsolutePath(userInput)) {
- QFileInfo fileInfo(QDir(workingDirectory), userInput);
- if ((options & AssumeLocalFile) || fileInfo.exists())
- return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
+ if ((options & AssumeLocalFile) && url.isRelative() && !QDir::isAbsolutePath(userInput)) {
+ return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
}
return fromUserInput(trimmedString);