diff options
author | Liang Qi <liang.qi@qt.io> | 2016-12-13 09:36:26 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-12-13 09:39:20 +0100 |
commit | 6755ec891a1740110c48895afd53d39e8370704a (patch) | |
tree | 982606f3bc582262e4b315a63f55ccb141fff97b /src/corelib/io | |
parent | 449204f8c0d6679ae0e58dbb8a30b8a86fbdb4ec (diff) | |
parent | 00c9ec63a552d040e851b561c11428fabf1a2b08 (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
configure
qmake/Makefile.unix.macos
qmake/Makefile.unix.win32
qmake/generators/win32/msvc_vcproj.cpp
src/3rdparty/pcre/qt_attribution.json
src/corelib/io/qsettings.cpp
src/corelib/kernel/qdeadlinetimer.cpp
src/platformsupport/kmsconvenience/qkmsdevice.cpp
src/platformsupport/kmsconvenience/qkmsdevice_p.h
src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp
src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp
src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp
src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp
src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.h
tests/manual/qstorageinfo/printvolumes.cpp
tools/configure/configureapp.cpp
Change-Id: Ibaabcc8e965c44926f9fb018466e8b132b8df49e
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/PSL-LICENSE.txt | 373 | ||||
-rw-r--r-- | src/corelib/io/qdir.cpp | 126 | ||||
-rw-r--r-- | src/corelib/io/qfile_p.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 20 | ||||
-rw-r--r-- | src/corelib/io/qresource.cpp | 126 | ||||
-rw-r--r-- | src/corelib/io/qresource.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qsettings.cpp | 72 | ||||
-rw-r--r-- | src/corelib/io/qt_attribution.json | 29 | ||||
-rw-r--r-- | src/corelib/io/qtemporaryfile_p.h | 14 | ||||
-rw-r--r-- | src/corelib/io/qurl.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qurltlds_p.h.INFO | 3 |
11 files changed, 615 insertions, 157 deletions
diff --git a/src/corelib/io/PSL-LICENSE.txt b/src/corelib/io/PSL-LICENSE.txt new file mode 100644 index 0000000000..d0a1fa1482 --- /dev/null +++ b/src/corelib/io/PSL-LICENSE.txt @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 91953ebf26..437f774547 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -80,6 +80,40 @@ static QString driveSpec(const QString &path) } #endif +enum { +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + OSSupportsUncPaths = true +#else + OSSupportsUncPaths = false +#endif +}; + +// Return the length of the root part of an absolute path, for use by cleanPath(), cd(). +static int rootLength(const QString &name, bool allowUncPaths) +{ + const int len = name.length(); + // starts with double slash + if (allowUncPaths && name.startsWith(QLatin1String("//"))) { + // Server name '//server/path' is part of the prefix. + const int nextSlash = name.indexOf(QLatin1Char('/'), 2); + return nextSlash >= 0 ? nextSlash + 1 : len; + } +#if defined(Q_OS_WINRT) + const QString rootPath = QDir::rootPath(); // rootPath contains the trailing slash + if (name.startsWith(rootPath, Qt::CaseInsensitive)) + return rootPath.size(); +#endif // Q_OS_WINRT +#if defined(Q_OS_WIN) + if (len >= 2 && name.at(1) == QLatin1Char(':')) { + // Handle a possible drive letter + return len > 2 && name.at(2) == QLatin1Char('/') ? 3 : 2; + } +#endif + if (name.at(0) == QLatin1Char('/')) + return 1; + return 0; +} + //************* QDirPrivate QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, QDir::SortFlags sort_, QDir::Filters filters_) : QSharedData() @@ -859,6 +893,8 @@ QString QDir::fromNativeSeparators(const QString &pathName) return pathName; } +static QString qt_cleanPath(const QString &path, bool *ok = nullptr); + /*! Changes the QDir's directory to \a dirName. @@ -879,32 +915,18 @@ bool QDir::cd(const QString &dirName) return true; QString newPath; if (isAbsolutePath(dirName)) { - newPath = cleanPath(dirName); + newPath = qt_cleanPath(dirName); } else { - if (isRoot()) - newPath = d->dirEntry.filePath(); - else - newPath = d->dirEntry.filePath() % QLatin1Char('/'); + newPath = d->dirEntry.filePath(); + if (!newPath.endsWith(QLatin1Char('/'))) + newPath += QLatin1Char('/'); newPath += dirName; if (dirName.indexOf(QLatin1Char('/')) >= 0 || dirName == QLatin1String("..") || d->dirEntry.filePath() == QLatin1String(".")) { - newPath = cleanPath(newPath); -#if defined (Q_OS_UNIX) - //After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root. - if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/..")) -#elif defined (Q_OS_WINRT) - const QString rootPath = QDir::rootPath(); - if (newPath.size() < rootPath.size() && rootPath.startsWith(newPath)) -#else - /* - cleanPath() already took care of replacing '\' with '/'. - We can't use startsWith here because the letter of the drive is unknown. - After cleanPath() if path is "[A-Z]:/.." or starts with "[A-Z]:/../" it means trying to cd above root. - */ - - if (newPath.midRef(1, 4) == QLatin1String(":/..") && (newPath.length() == 5 || newPath.at(5) == QLatin1Char('/'))) -#endif + bool ok; + newPath = qt_cleanPath(newPath, &ok); + if (!ok) return false; /* If newPath starts with .., we convert it to absolute to @@ -2051,10 +2073,14 @@ bool QDir::match(const QString &filter, const QString &fileName) This method is shared with QUrl, so it doesn't deal with QDir::separator(), nor does it remove the trailing slash, if any. */ -Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool allowUncPaths) +Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool allowUncPaths, + bool *ok = nullptr) { const int len = name.length(); + if (ok) + *ok = false; + if (len == 0) return name; @@ -2066,19 +2092,7 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all const QChar *prefix = p; int up = 0; - int prefixLength = 0; - - if (allowUncPaths && len >= 2 && p[1].unicode() == '/' && p[0].unicode() == '/') { - // starts with double slash - prefixLength = 2; -#ifdef Q_OS_WIN - } else if (len >= 2 && p[1].unicode() == ':') { - // remember the drive letter - prefixLength = (len > 2 && p[2].unicode() == '/') ? 3 : 2; -#endif - } else if (p[0].unicode() == '/') { - prefixLength = 1; - } + const int prefixLength = rootLength(name, allowUncPaths); p += prefixLength; i -= prefixLength; @@ -2131,6 +2145,10 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all --up; } + // Indicate failure when ".." are left over for an absolute path. + if (ok) + *ok = prefixLength == 0 || up == 0; + // add remaining '..' while (up) { if (used != len && out[used].unicode() != '/') // is not empty and there isn't already a '/' @@ -2168,32 +2186,16 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all return ret; } -/*! - Returns \a path with directory separators normalized (converted to "/") and - redundant ones removed, and "."s and ".."s resolved (as far as possible). - - Symbolic links are kept. This function does not return the - canonical path, but rather the simplest version of the input. - For example, "./local" becomes "local", "local/../bin" becomes - "bin" and "/local/usr/../bin" becomes "/local/bin". - - \sa absolutePath(), canonicalPath() -*/ -QString QDir::cleanPath(const QString &path) +static QString qt_cleanPath(const QString &path, bool *ok) { if (path.isEmpty()) return path; QString name = path; - QChar dir_separator = separator(); + QChar dir_separator = QDir::separator(); if (dir_separator != QLatin1Char('/')) name.replace(dir_separator, QLatin1Char('/')); - bool allowUncPaths = false; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //allow unc paths - allowUncPaths = true; -#endif - - QString ret = qt_normalizePathSegments(name, allowUncPaths); + QString ret = qt_normalizePathSegments(name, OSSupportsUncPaths, ok); // Strip away last slash except for root directories if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) { @@ -2211,6 +2213,22 @@ QString QDir::cleanPath(const QString &path) } /*! + Returns \a path with directory separators normalized (converted to "/") and + redundant ones removed, and "."s and ".."s resolved (as far as possible). + + Symbolic links are kept. This function does not return the + canonical path, but rather the simplest version of the input. + For example, "./local" becomes "local", "local/../bin" becomes + "bin" and "/local/usr/../bin" becomes "/local/bin". + + \sa absolutePath(), canonicalPath() +*/ +QString QDir::cleanPath(const QString &path) +{ + return qt_cleanPath(path); +} + +/*! Returns \c true if \a path is relative; returns \c false if it is absolute. diff --git a/src/corelib/io/qfile_p.h b/src/corelib/io/qfile_p.h index fd7db3c120..545890c6b3 100644 --- a/src/corelib/io/qfile_p.h +++ b/src/corelib/io/qfile_p.h @@ -70,7 +70,7 @@ protected: bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags); bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags); - virtual QAbstractFileEngine *engine() const; + QAbstractFileEngine *engine() const override; QString fileName; }; diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 5de85f9811..1b908eac55 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -65,6 +65,13 @@ #include <MobileCoreServices/MobileCoreServices.h> #endif +#if defined(Q_OS_DARWIN) +// We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but +// we need these declarations: +Q_FORWARD_DECLARE_OBJC_CLASS(NSString); +extern "C" NSString *NSTemporaryDirectory(); +#endif + QT_BEGIN_NAMESPACE #if defined(Q_OS_DARWIN) @@ -703,8 +710,17 @@ QString QFileSystemEngine::tempPath() return QLatin1String(QT_UNIX_TEMP_PATH_OVERRIDE); #else QString temp = QFile::decodeName(qgetenv("TMPDIR")); - if (temp.isEmpty()) - temp = QLatin1String("/tmp"); + if (temp.isEmpty()) { +#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED) + if (NSString *nsPath = NSTemporaryDirectory()) { + temp = QString::fromCFString((CFStringRef)nsPath); + } else { +#else + { +#endif + temp = QLatin1String("/tmp"); + } + } return QDir::cleanPath(temp); #endif } diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 7fe3753da4..febf22639c 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -49,6 +49,7 @@ #include "qdatetime.h" #include "qbytearray.h" #include "qstringlist.h" +#include "qendian.h" #include <qshareddata.h> #include <qplatformdefs.h> #include "private/qabstractfileengine_p.h" @@ -101,35 +102,38 @@ class QResourceRoot Directory = 0x02 }; const uchar *tree, *names, *payloads; - inline int findOffset(int node) const { return node * 14; } //sizeof each tree element + int version; + inline int findOffset(int node) const { return node * (14 + (version >= 0x02 ? 8 : 0)); } //sizeof each tree element uint hash(int node) const; QString name(int node) const; short flags(int node) const; public: mutable QAtomicInt ref; - inline QResourceRoot(): tree(0), names(0), payloads(0) {} - inline QResourceRoot(const uchar *t, const uchar *n, const uchar *d) { setSource(t, n, d); } + inline QResourceRoot(): tree(0), names(0), payloads(0), version(0) {} + inline QResourceRoot(int version, const uchar *t, const uchar *n, const uchar *d) { setSource(version, t, n, d); } virtual ~QResourceRoot() { } int findNode(const QString &path, const QLocale &locale=QLocale()) const; inline bool isContainer(int node) const { return flags(node) & Directory; } inline bool isCompressed(int node) const { return flags(node) & Compressed; } const uchar *data(int node, qint64 *size) const; + QDateTime lastModified(int node) const; QStringList children(int node) const; virtual QString mappingRoot() const { return QString(); } bool mappingRootSubdir(const QString &path, QString *match=0) const; inline bool operator==(const QResourceRoot &other) const - { return tree == other.tree && names == other.names && payloads == other.payloads; } + { return tree == other.tree && names == other.names && payloads == other.payloads && version == other.version; } inline bool operator!=(const QResourceRoot &other) const { return !operator==(other); } enum ResourceRootType { Resource_Builtin, Resource_File, Resource_Buffer }; virtual ResourceRootType type() const { return Resource_Builtin; } protected: - inline void setSource(const uchar *t, const uchar *n, const uchar *d) { + inline void setSource(int v, const uchar *t, const uchar *n, const uchar *d) { tree = t; names = n; payloads = d; + version = v; } }; @@ -231,6 +235,7 @@ public: mutable qint64 size; mutable const uchar *data; mutable QStringList children; + mutable QDateTime lastModified; QResource *q_ptr; Q_DECLARE_PUBLIC(QResource) @@ -244,6 +249,7 @@ QResourcePrivate::clear() data = 0; size = 0; children.clear(); + lastModified = QDateTime(); container = 0; for(int i = 0; i < related.size(); ++i) { QResourceRoot *root = related.at(i); @@ -274,6 +280,7 @@ QResourcePrivate::load(const QString &file) size = 0; compressed = 0; } + lastModified = res->lastModified(node); } else if(res->isContainer(node) != container) { qWarning("QResourceInfo: Resource [%s] has both data and children!", file.toLatin1().constData()); } @@ -284,6 +291,7 @@ QResourcePrivate::load(const QString &file) data = 0; size = 0; compressed = 0; + lastModified = QDateTime(); res->ref.ref(); related.append(res); } @@ -514,6 +522,17 @@ const uchar *QResource::data() const } /*! + Returns the date and time when the file was last modified before + packaging into a resource. +*/ +QDateTime QResource::lastModified() const +{ + Q_D(const QResource); + d->ensureInitialized(); + return d->lastModified; +} + +/*! Returns \c true if the resource represents a directory and thus may have children() in it, false if it represents a file. @@ -588,11 +607,9 @@ inline uint QResourceRoot::hash(int node) const if(!node) //root return 0; const int offset = findOffset(node); - int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + qint32 name_offset = qFromBigEndian<qint32>(tree + offset); name_offset += 2; //jump past name length - return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) + - (names[name_offset+2] << 8) + (names[name_offset+3] << 0); + return qFromBigEndian<quint32>(names + name_offset); } inline QString QResourceRoot::name(int node) const { @@ -601,10 +618,8 @@ inline QString QResourceRoot::name(int node) const const int offset = findOffset(node); QString ret; - int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); - const short name_length = (names[name_offset+0] << 8) + - (names[name_offset+1] << 0); + qint32 name_offset = qFromBigEndian<qint32>(tree + offset); + const qint16 name_length = qFromBigEndian<qint16>(names + name_offset); name_offset += 2; name_offset += 4; //jump past hash @@ -644,10 +659,8 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const return 0; //the root node is always first - int child_count = (tree[6] << 24) + (tree[7] << 16) + - (tree[8] << 8) + (tree[9] << 0); - int child = (tree[10] << 24) + (tree[11] << 16) + - (tree[12] << 8) + (tree[13] << 0); + qint32 child_count = qFromBigEndian<qint32>(tree + 6); + qint32 child = qFromBigEndian<qint32>(tree + 10); //now iterate up the tree int node = -1; @@ -693,18 +706,15 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const #endif offset += 4; //jump past name - const short flags = (tree[offset+0] << 8) + - (tree[offset+1] << 0); + const qint16 flags = qFromBigEndian<qint16>(tree + offset); offset += 2; if(!splitter.hasNext()) { if(!(flags & Directory)) { - const short country = (tree[offset+0] << 8) + - (tree[offset+1] << 0); + const qint16 country = qFromBigEndian<qint16>(tree + offset); offset += 2; - const short language = (tree[offset+0] << 8) + - (tree[offset+1] << 0); + const qint16 language = qFromBigEndian<qint16>(tree + offset); offset += 2; #ifdef DEBUG_RESOURCE_MATCH qDebug() << " " << "LOCALE" << country << language; @@ -731,11 +741,9 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const if(!(flags & Directory)) return -1; - child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + child_count = qFromBigEndian<qint32>(tree + offset); offset += 4; - child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + child = qFromBigEndian<qint32>(tree + offset); break; } } @@ -753,7 +761,7 @@ short QResourceRoot::flags(int node) const if(node == -1) return 0; const int offset = findOffset(node) + 4; //jump past name - return (tree[offset+0] << 8) + (tree[offset+1] << 0); + return qFromBigEndian<qint16>(tree + offset); } const uchar *QResourceRoot::data(int node, qint64 *size) const { @@ -763,16 +771,14 @@ const uchar *QResourceRoot::data(int node, qint64 *size) const } int offset = findOffset(node) + 4; //jump past name - const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); + const qint16 flags = qFromBigEndian<qint16>(tree + offset); offset += 2; offset += 4; //jump past locale if(!(flags & Directory)) { - const int data_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); - const uint data_length = (payloads[data_offset+0] << 24) + (payloads[data_offset+1] << 16) + - (payloads[data_offset+2] << 8) + (payloads[data_offset+3] << 0); + const qint32 data_offset = qFromBigEndian<qint32>(tree + offset); + const quint32 data_length = qFromBigEndian<quint32>(payloads + data_offset); const uchar *ret = payloads+data_offset+4; *size = data_length; return ret; @@ -780,22 +786,35 @@ const uchar *QResourceRoot::data(int node, qint64 *size) const *size = 0; return 0; } + +QDateTime QResourceRoot::lastModified(int node) const +{ + if (node == -1 || version < 0x02) + return QDateTime(); + + const int offset = findOffset(node) + 14; + + const quint64 timeStamp = qFromBigEndian<quint64>(tree + offset); + if (timeStamp == 0) + return QDateTime(); + + return QDateTime::fromMSecsSinceEpoch(timeStamp); +} + QStringList QResourceRoot::children(int node) const { if(node == -1) return QStringList(); int offset = findOffset(node) + 4; //jump past name - const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); + const qint16 flags = qFromBigEndian<qint16>(tree + offset); offset += 2; QStringList ret; if(flags & Directory) { - const int child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + const qint32 child_count = qFromBigEndian<qint32>(tree + offset); offset += 4; - const int child_off = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + const qint32 child_off = qFromBigEndian<qint32>(tree + offset); ret.reserve(child_count); for(int i = child_off; i < child_off+child_count; ++i) ret << name(i); @@ -829,9 +848,9 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data) { QMutexLocker lock(resourceMutex()); - if(version == 0x01 && resourceList()) { + if ((version == 0x01 || version == 0x2) && resourceList()) { bool found = false; - QResourceRoot res(tree, name, data); + QResourceRoot res(version, tree, name, data); for(int i = 0; i < resourceList()->size(); ++i) { if(*resourceList()->at(i) == res) { found = true; @@ -839,7 +858,7 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, } } if(!found) { - QResourceRoot *root = new QResourceRoot(tree, name, data); + QResourceRoot *root = new QResourceRoot(version, tree, name, data); root->ref.ref(); resourceList()->append(root); } @@ -852,8 +871,8 @@ Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tre const unsigned char *name, const unsigned char *data) { QMutexLocker lock(resourceMutex()); - if(version == 0x01 && resourceList()) { - QResourceRoot res(tree, name, data); + if ((version == 0x01 || version == 0x02) && resourceList()) { + QResourceRoot res(version, tree, name, data); for(int i = 0; i < resourceList()->size(); ) { if(*resourceList()->at(i) == res) { QResourceRoot *root = resourceList()->takeAt(i); @@ -899,29 +918,25 @@ public: } offset += 4; - const int version = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int version = qFromBigEndian<qint32>(b + offset); offset += 4; - const int tree_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int tree_offset = qFromBigEndian<qint32>(b + offset); offset += 4; - const int data_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int data_offset = qFromBigEndian<qint32>(b + offset); offset += 4; - const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int name_offset = qFromBigEndian<qint32>(b + offset); offset += 4; // Some sanity checking for sizes. This is _not_ a security measure. if (size >= 0 && (tree_offset >= size || data_offset >= size || name_offset >= size)) return false; - if(version == 0x01) { + if (version == 0x01 || version == 0x02) { buffer = b; - setSource(b+tree_offset, b+name_offset, b+data_offset); + setSource(version, b+tree_offset, b+name_offset, b+data_offset); return true; } return false; @@ -1430,8 +1445,11 @@ QString QResourceFileEngine::owner(FileOwner) const return QString(); } -QDateTime QResourceFileEngine::fileTime(FileTime) const +QDateTime QResourceFileEngine::fileTime(FileTime time) const { + Q_D(const QResourceFileEngine); + if (time == ModificationTime) + return d->resource.lastModified(); return QDateTime(); } diff --git a/src/corelib/io/qresource.h b/src/corelib/io/qresource.h index a50bbbdaca..895cf0456e 100644 --- a/src/corelib/io/qresource.h +++ b/src/corelib/io/qresource.h @@ -69,6 +69,7 @@ public: bool isCompressed() const; qint64 size() const; const uchar *data() const; + QDateTime lastModified() const; static void addSearchPath(const QString &path); static QStringList searchPaths(); diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 675b375b22..1a69891d3b 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -97,14 +97,6 @@ using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Storage; #endif -#ifndef CSIDL_COMMON_APPDATA -#define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data -#endif - -#ifndef CSIDL_APPDATA -#define CSIDL_APPDATA 0x001a // <username>\Application Data -#endif - #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_ANDROID) #define Q_XDG_PLATFORM #endif @@ -970,31 +962,34 @@ void QConfFileSettingsPrivate::initAccess() } #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -static QString windowsConfigPath(int type) +static QString windowsConfigPath(const KNOWNFOLDERID &type) { QString result; - wchar_t path[MAX_PATH]; - if (SHGetSpecialFolderPath(0, path, type, false)) + PWSTR path = nullptr; + if (SHGetKnownFolderPath(type, KF_FLAG_DONT_VERIFY, NULL, &path) == S_OK) { result = QString::fromWCharArray(path); + CoTaskMemFree(path); + } if (result.isEmpty()) { - switch (type) { - case CSIDL_COMMON_APPDATA: + if (type == FOLDERID_ProgramData) { result = QLatin1String("C:\\temp\\qt-common"); - break; - case CSIDL_APPDATA: + } else if (type == FOLDERID_RoamingAppData) { result = QLatin1String("C:\\temp\\qt-user"); - break; - default: - ; } } return result; } #elif defined(Q_OS_WINRT) // Q_OS_WIN && !Q_OS_WINRT -static QString windowsConfigPath(int type) + +enum ConfigPathType { + ConfigPath_CommonAppData, + ConfigPath_UserAppData +}; + +static QString windowsConfigPath(ConfigPathType type) { static QString result; while (result.isEmpty()) { @@ -1017,12 +1012,10 @@ static QString windowsConfigPath(int type) } switch (type) { - case CSIDL_COMMON_APPDATA: + case ConfigPath_CommonAppData: return result + QLatin1String("\\qt-common"); - case CSIDL_APPDATA: + case ConfigPath_UserAppData: return result + QLatin1String("\\qt-user"); - default: - break; } return result; } @@ -1079,10 +1072,18 @@ static void initDefaultPaths(QMutexLocker *locker) Windows registry and the Mac CFPreferences.) */ #ifdef Q_OS_WIN + +# ifdef Q_OS_WINRT + const QString roamingAppDataFolder = windowsConfigPath(ConfigPath_UserAppData); + const QString programDataFolder = windowsConfigPath(ConfigPath_CommonAppData); +# else + const QString roamingAppDataFolder = windowsConfigPath(FOLDERID_RoamingAppData); + const QString programDataFolder = windowsConfigPath(FOLDERID_ProgramData); +# endif pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), - Path(windowsConfigPath(CSIDL_APPDATA) + QDir::separator(), false)); + Path(roamingAppDataFolder + QDir::separator(), false)); pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), - Path(windowsConfigPath(CSIDL_COMMON_APPDATA) + QDir::separator(), false)); + Path(programDataFolder + QDir::separator(), false)); #else const QString userPath = make_user_path(); pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), Path(userPath, false)); @@ -2267,20 +2268,20 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, On Windows, the following files are used: \list 1 - \li \c{CSIDL_APPDATA\MySoft\Star Runner.ini} - \li \c{CSIDL_APPDATA\MySoft.ini} - \li \c{CSIDL_COMMON_APPDATA\MySoft\Star Runner.ini} - \li \c{CSIDL_COMMON_APPDATA\MySoft.ini} + \li \c{FOLDERID_RoamingAppData\MySoft\Star Runner.ini} + \li \c{FOLDERID_RoamingAppData\MySoft.ini} + \li \c{FOLDERID_ProgramData\MySoft\Star Runner.ini} + \li \c{FOLDERID_ProgramData\MySoft.ini} \endlist - The identifiers prefixed by \c{CSIDL_} are special item ID lists to be passed - to the Win32 API function \c{SHGetSpecialFolderPath()} to obtain the + The identifiers prefixed by \c{FOLDERID_} are special item ID lists to be passed + to the Win32 API function \c{SHGetKnownFolderPath()} to obtain the corresponding path. - \c{CSIDL_APPDATA} usually points to \tt{C:\\Users\\\e{User Name}\\AppData\\Roaming}, + \c{FOLDERID_RoamingAppData} usually points to \tt{C:\\Users\\\e{User Name}\\AppData\\Roaming}, also shown by the environment variable \c{%APPDATA%}. - \c{CSIDL_COMMON_APPDATA} usually points to \tt{C:\\ProgramData}. + \c{FOLDERID_ProgramData} usually points to \tt{C:\\ProgramData}. If the file format is IniFormat, this is "Settings/MySoft/Star Runner.ini" in the application's home directory. @@ -2740,6 +2741,7 @@ void QSettings::sync() { Q_D(QSettings); d->sync(); + d->pendingChanges = false; } /*! @@ -3384,8 +3386,8 @@ void QSettings::setUserIniPath(const QString &dir) \table \header \li Platform \li Format \li Scope \li Path - \row \li{1,2} Windows \li{1,2} IniFormat \li UserScope \li \c CSIDL_APPDATA - \row \li SystemScope \li \c CSIDL_COMMON_APPDATA + \row \li{1,2} Windows \li{1,2} IniFormat \li UserScope \li \c FOLDERID_RoamingAppData + \row \li SystemScope \li \c FOLDERID_ProgramData \row \li{1,2} Unix \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/.config \row \li SystemScope \li \c /etc/xdg \row \li{1,2} Qt for Embedded Linux \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/Settings diff --git a/src/corelib/io/qt_attribution.json b/src/corelib/io/qt_attribution.json index 2a616a2819..c64f8cae4b 100644 --- a/src/corelib/io/qt_attribution.json +++ b/src/corelib/io/qt_attribution.json @@ -1,3 +1,4 @@ +[ { "Id": "qtemporaryfile", "Name": "Parts of QTemporaryFile", @@ -10,4 +11,32 @@ "LicenseId": "BSD-3-Clause", "LicenseFile": "QTEMPORARYFILE_LICENSE.txt", "Copyright": "Copyright (c) 1987, 1993 The Regents of the University of California." +}, +{ + "Id": "psl", + "Name": "The Public Suffix List", + "QDocModule": "qtcore", + "Description": "The Public Suffix List is an initiative of the Mozilla Project, +but is maintained as a community resource. It is available for use in any software, +but was originally created to meet the needs of browser manufacturers. +It allows browsers to, for example: + +- Avoid privacy-damaging \"supercookies\" being set for high-level domain name suffixes + +- Highlight the most important part of a domain name in the user interface + +- Accurately sort history entries by site", + + "Files": "qurltlds_p.h", + "QtUsage": "Used in Qt Core to avoid \"supercookies\" being set in the cookie jar +supported by Qt (by the QNetworkCookieJar class).", + + "Homepage": "http://publicsuffix.org/", + "Version": "Generated on 2016-10-20 from revision 915565885d0fbd25caf7d8b339cd3478f558da94", + "License": "Mozilla Public License 2.0", + "LicenseFile": "PSL-LICENSE.txt", + "LicenseId": "MPL-2.0", + "Copyright": "The list was originally provided by Jo Hermans <jo.hermans@gmail.com>. +It is now maintained on github (https://github.com/publicsuffix/list)." } +] diff --git a/src/corelib/io/qtemporaryfile_p.h b/src/corelib/io/qtemporaryfile_p.h index d057603034..7f365f0e8a 100644 --- a/src/corelib/io/qtemporaryfile_p.h +++ b/src/corelib/io/qtemporaryfile_p.h @@ -70,7 +70,7 @@ protected: explicit QTemporaryFilePrivate(const QString &templateNameIn); ~QTemporaryFilePrivate(); - QAbstractFileEngine *engine() const; + QAbstractFileEngine *engine() const override; void resetFileEngine() const; bool autoRemove = true; @@ -99,14 +99,14 @@ public: ~QTemporaryFileEngine(); bool isReallyOpen() const; - void setFileName(const QString &file); + void setFileName(const QString &file) override; void setFileTemplate(const QString &fileTemplate); - bool open(QIODevice::OpenMode flags); - bool remove(); - bool rename(const QString &newName); - bool renameOverwrite(const QString &newName); - bool close(); + bool open(QIODevice::OpenMode flags) override; + bool remove() override; + bool rename(const QString &newName) override; + bool renameOverwrite(const QString &newName) override; + bool close() override; quint32 fileMode; bool filePathIsTemplate; diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 5b34813a71..066052ade9 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -417,7 +417,8 @@ #include "qurlquery.h" QT_BEGIN_NAMESPACE -extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths); // qdir.cpp +extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths, + bool *ok = nullptr); // qdir.cpp inline static bool isHex(char c) { @@ -3690,6 +3691,9 @@ bool QUrl::matches(const QUrl &url, FormattingOptions options) const if ((d->sectionIsPresent & mask) != (url.d->sectionIsPresent & mask)) return false; + if (options & QUrl::RemovePath) + return true; + // Compare paths, after applying path-related options QString path1; d->appendPath(path1, options, QUrlPrivate::Path); diff --git a/src/corelib/io/qurltlds_p.h.INFO b/src/corelib/io/qurltlds_p.h.INFO index 3f3d808a21..33ccd458bf 100644 --- a/src/corelib/io/qurltlds_p.h.INFO +++ b/src/corelib/io/qurltlds_p.h.INFO @@ -9,9 +9,6 @@ Those arrays in qurltlds_p.h are derived from the Public Suffix List ([2]), which was originally provided by Jo Hermans <jo.hermans@gmail.com>. -The file qurltlds_p.h was last generated Thursday, -October 20th 8:40 2016. - ---- [1] list: http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1 [2] homepage: http://publicsuffix.org/ |