| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystementry.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qfilesystementry_p.h" | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include <QtCore/qdir.h> | - | ||||||||||||
| 43 | #include <QtCore/qfile.h> | - | ||||||||||||
| 44 | #include <QtCore/private/qfsfileengine_p.h> | - | ||||||||||||
| 45 | #ifdef Q_OS_WIN | - | ||||||||||||
| 46 | #include <QtCore/qstringbuilder.h> | - | ||||||||||||
| 47 | #endif | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | #ifdef Q_OS_WIN | - | ||||||||||||
| 52 | static bool isUncRoot(const QString &server) | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | QString localPath = QDir::toNativeSeparators(server); | - | ||||||||||||
| 55 | if (!localPath.startsWith(QLatin1String("\\\\"))) | - | ||||||||||||
| 56 | return false; | - | ||||||||||||
| 57 | - | |||||||||||||
| 58 | int idx = localPath.indexOf(QLatin1Char('\\'), 2); | - | ||||||||||||
| 59 | if (idx == -1 || idx + 1 == localPath.length()) | - | ||||||||||||
| 60 | return true; | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | return localPath.rightRef(localPath.length() - idx - 1).trimmed().isEmpty(); | - | ||||||||||||
| 63 | } | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | static inline QString fixIfRelativeUncPath(const QString &path) | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | QString currentPath = QDir::currentPath(); | - | ||||||||||||
| 68 | if (currentPath.startsWith(QLatin1String("//"))) | - | ||||||||||||
| 69 | return currentPath % QChar(QLatin1Char('/')) % path; | - | ||||||||||||
| 70 | return path; | - | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | #endif | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | QFileSystemEntry::QFileSystemEntry() | - | ||||||||||||
| 75 | : m_lastSeparator(-1), | - | ||||||||||||
| 76 | m_firstDotInFileName(-1), | - | ||||||||||||
| 77 | m_lastDotInFileName(-1) | - | ||||||||||||
| 78 | { | - | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | /*! | - | ||||||||||||
| 82 | \internal | - | ||||||||||||
| 83 | Use this constructor when the path is supplied by user code, as it may contain a mix | - | ||||||||||||
| 84 | of '/' and the native separator. | - | ||||||||||||
| 85 | */ | - | ||||||||||||
| 86 | QFileSystemEntry::QFileSystemEntry(const QString &filePath) | - | ||||||||||||
| 87 | : m_filePath(QDir::fromNativeSeparators(filePath)), | - | ||||||||||||
| 88 | m_lastSeparator(-2), | - | ||||||||||||
| 89 | m_firstDotInFileName(-2), | - | ||||||||||||
| 90 | m_lastDotInFileName(0) | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | } | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | /*! | - | ||||||||||||
| 95 | \internal | - | ||||||||||||
| 96 | Use this constructor when the path is guaranteed to be in internal format, i.e. all | - | ||||||||||||
| 97 | directory separators are '/' and not the native separator. | - | ||||||||||||
| 98 | */ | - | ||||||||||||
| 99 | QFileSystemEntry::QFileSystemEntry(const QString &filePath, FromInternalPath /* dummy */) | - | ||||||||||||
| 100 | : m_filePath(filePath), | - | ||||||||||||
| 101 | m_lastSeparator(-2), | - | ||||||||||||
| 102 | m_firstDotInFileName(-2), | - | ||||||||||||
| 103 | m_lastDotInFileName(0) | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | /*! | - | ||||||||||||
| 108 | \internal | - | ||||||||||||
| 109 | Use this constructor when the path comes from a native API | - | ||||||||||||
| 110 | */ | - | ||||||||||||
| 111 | QFileSystemEntry::QFileSystemEntry(const NativePath &nativeFilePath, FromNativePath /* dummy */) | - | ||||||||||||
| 112 | : m_nativeFilePath(nativeFilePath), | - | ||||||||||||
| 113 | m_lastSeparator(-2), | - | ||||||||||||
| 114 | m_firstDotInFileName(-2), | - | ||||||||||||
| 115 | m_lastDotInFileName(0) | - | ||||||||||||
| 116 | { | - | ||||||||||||
| 117 | } | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | QFileSystemEntry::QFileSystemEntry(const QString &filePath, const NativePath &nativeFilePath) | - | ||||||||||||
| 120 | : m_filePath(QDir::fromNativeSeparators(filePath)), | - | ||||||||||||
| 121 | m_nativeFilePath(nativeFilePath), | - | ||||||||||||
| 122 | m_lastSeparator(-2), | - | ||||||||||||
| 123 | m_firstDotInFileName(-2), | - | ||||||||||||
| 124 | m_lastDotInFileName(0) | - | ||||||||||||
| 125 | { | - | ||||||||||||
| 126 | } | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | QString QFileSystemEntry::filePath() const | - | ||||||||||||
| 129 | { | - | ||||||||||||
| 130 | resolveFilePath(); | - | ||||||||||||
| 131 | return m_filePath; | - | ||||||||||||
| 132 | } | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | QFileSystemEntry::NativePath QFileSystemEntry::nativeFilePath() const | - | ||||||||||||
| 135 | { | - | ||||||||||||
| 136 | resolveNativeFilePath(); | - | ||||||||||||
| 137 | return m_nativeFilePath; | - | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | void QFileSystemEntry::resolveFilePath() const | - | ||||||||||||
| 141 | { | - | ||||||||||||
| 142 | if (m_filePath.isEmpty() && !m_nativeFilePath.isEmpty()) { | - | ||||||||||||
| 143 | #if defined(QFILESYSTEMENTRY_NATIVE_PATH_IS_UTF16) | - | ||||||||||||
| 144 | m_filePath = QDir::fromNativeSeparators(m_nativeFilePath); | - | ||||||||||||
| 145 | #ifdef Q_OS_WIN | - | ||||||||||||
| 146 | if (m_filePath.startsWith(QLatin1String("//?/UNC/"))) | - | ||||||||||||
| 147 | m_filePath = m_filePath.remove(2,6); | - | ||||||||||||
| 148 | if (m_filePath.startsWith(QLatin1String("//?/"))) | - | ||||||||||||
| 149 | m_filePath = m_filePath.remove(0,4); | - | ||||||||||||
| 150 | #endif | - | ||||||||||||
| 151 | #else | - | ||||||||||||
| 152 | m_filePath = QDir::fromNativeSeparators(QFile::decodeName(m_nativeFilePath)); | - | ||||||||||||
| 153 | #endif | - | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | void QFileSystemEntry::resolveNativeFilePath() const | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | if (!m_filePath.isEmpty() && m_nativeFilePath.isEmpty()) { | - | ||||||||||||
| 160 | #ifdef Q_OS_WIN | - | ||||||||||||
| 161 | QString filePath = m_filePath; | - | ||||||||||||
| 162 | if (isRelative()) | - | ||||||||||||
| 163 | filePath = fixIfRelativeUncPath(m_filePath); | - | ||||||||||||
| 164 | m_nativeFilePath = QFSFileEnginePrivate::longFileName(QDir::toNativeSeparators(filePath)); | - | ||||||||||||
| 165 | #elif defined(QFILESYSTEMENTRY_NATIVE_PATH_IS_UTF16) | - | ||||||||||||
| 166 | m_nativeFilePath = QDir::toNativeSeparators(m_filePath); | - | ||||||||||||
| 167 | #else | - | ||||||||||||
| 168 | m_nativeFilePath = QFile::encodeName(QDir::toNativeSeparators(m_filePath)); | - | ||||||||||||
| 169 | #endif | - | ||||||||||||
| 170 | #ifdef Q_OS_WINRT | - | ||||||||||||
| 171 | while (m_nativeFilePath.startsWith(QLatin1Char('\\'))) | - | ||||||||||||
| 172 | m_nativeFilePath.remove(0,1); | - | ||||||||||||
| 173 | if (m_nativeFilePath.isEmpty()) | - | ||||||||||||
| 174 | m_nativeFilePath.append(QLatin1Char('.')); | - | ||||||||||||
| 175 | // WinRT/MSVC2015 allows a maximum of 256 characters for a filepath | - | ||||||||||||
| 176 | // unless //?/ is prepended which extends the rule to have a maximum | - | ||||||||||||
| 177 | // of 256 characters in the filename plus the preprending path | - | ||||||||||||
| 178 | #if _MSC_VER >= 1900 | - | ||||||||||||
| 179 | m_nativeFilePath.prepend("\\\\?\\"); | - | ||||||||||||
| 180 | #endif | - | ||||||||||||
| 181 | #endif | - | ||||||||||||
| 182 | } | - | ||||||||||||
| 183 | } | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | QString QFileSystemEntry::fileName() const | - | ||||||||||||
| 186 | { | - | ||||||||||||
| 187 | findLastSeparator(); | - | ||||||||||||
| 188 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 189 | if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':')) | - | ||||||||||||
| 190 | return m_filePath.mid(2); | - | ||||||||||||
| 191 | #endif | - | ||||||||||||
| 192 | return m_filePath.mid(m_lastSeparator + 1); | - | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | QString QFileSystemEntry::path() const | - | ||||||||||||
| 196 | { | - | ||||||||||||
| 197 | findLastSeparator(); | - | ||||||||||||
| 198 | if (m_lastSeparator == -1) { | - | ||||||||||||
| 199 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 200 | if (m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':')) | - | ||||||||||||
| 201 | return m_filePath.left(2); | - | ||||||||||||
| 202 | #endif | - | ||||||||||||
| 203 | return QString(QLatin1Char('.')); | - | ||||||||||||
| 204 | } | - | ||||||||||||
| 205 | if (m_lastSeparator == 0) | - | ||||||||||||
| 206 | return QString(QLatin1Char('/')); | - | ||||||||||||
| 207 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 208 | if (m_lastSeparator == 2 && m_filePath.at(1) == QLatin1Char(':')) | - | ||||||||||||
| 209 | return m_filePath.left(m_lastSeparator + 1); | - | ||||||||||||
| 210 | #endif | - | ||||||||||||
| 211 | return m_filePath.left(m_lastSeparator); | - | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | QString QFileSystemEntry::baseName() const | - | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | findFileNameSeparators(); | - | ||||||||||||
| 217 | int length = -1; | - | ||||||||||||
| 218 | if (m_firstDotInFileName >= 0) { | - | ||||||||||||
| 219 | length = m_firstDotInFileName; | - | ||||||||||||
| 220 | if (m_lastSeparator != -1) // avoid off by one | - | ||||||||||||
| 221 | length--; | - | ||||||||||||
| 222 | } | - | ||||||||||||
| 223 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 224 | if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':')) | - | ||||||||||||
| 225 | return m_filePath.mid(2, length - 2); | - | ||||||||||||
| 226 | #endif | - | ||||||||||||
| 227 | return m_filePath.mid(m_lastSeparator + 1, length); | - | ||||||||||||
| 228 | } | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | QString QFileSystemEntry::completeBaseName() const | - | ||||||||||||
| 231 | { | - | ||||||||||||
| 232 | findFileNameSeparators(); | - | ||||||||||||
| 233 | int length = -1; | - | ||||||||||||
| 234 | if (m_firstDotInFileName >= 0) { | - | ||||||||||||
| 235 | length = m_firstDotInFileName + m_lastDotInFileName; | - | ||||||||||||
| 236 | if (m_lastSeparator != -1) // avoid off by one | - | ||||||||||||
| 237 | length--; | - | ||||||||||||
| 238 | } | - | ||||||||||||
| 239 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 240 | if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':')) | - | ||||||||||||
| 241 | return m_filePath.mid(2, length - 2); | - | ||||||||||||
| 242 | #endif | - | ||||||||||||
| 243 | return m_filePath.mid(m_lastSeparator + 1, length); | - | ||||||||||||
| 244 | } | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | QString QFileSystemEntry::suffix() const | - | ||||||||||||
| 247 | { | - | ||||||||||||
| 248 | findFileNameSeparators(); | - | ||||||||||||
| 249 | - | |||||||||||||
| 250 | if (m_lastDotInFileName == -1) | - | ||||||||||||
| 251 | return QString(); | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | return m_filePath.mid(qMax((qint16)0, m_lastSeparator) + m_firstDotInFileName + m_lastDotInFileName + 1); | - | ||||||||||||
| 254 | } | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | QString QFileSystemEntry::completeSuffix() const | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | findFileNameSeparators(); | - | ||||||||||||
| 259 | if (m_firstDotInFileName == -1) | - | ||||||||||||
| 260 | return QString(); | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | return m_filePath.mid(qMax((qint16)0, m_lastSeparator) + m_firstDotInFileName + 1); | - | ||||||||||||
| 263 | } | - | ||||||||||||
| 264 | - | |||||||||||||
| 265 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 266 | bool QFileSystemEntry::isRelative() const | - | ||||||||||||
| 267 | { | - | ||||||||||||
| 268 | resolveFilePath(); | - | ||||||||||||
| 269 | return (m_filePath.isEmpty() | - | ||||||||||||
| 270 | || (m_filePath.at(0).unicode() != '/' | - | ||||||||||||
| 271 | && !(m_filePath.length() >= 2 && m_filePath.at(1).unicode() == ':'))); | - | ||||||||||||
| 272 | } | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | bool QFileSystemEntry::isAbsolute() const | - | ||||||||||||
| 275 | { | - | ||||||||||||
| 276 | resolveFilePath(); | - | ||||||||||||
| 277 | return ((m_filePath.length() >= 3 | - | ||||||||||||
| 278 | && m_filePath.at(0).isLetter() | - | ||||||||||||
| 279 | && m_filePath.at(1).unicode() == ':' | - | ||||||||||||
| 280 | && m_filePath.at(2).unicode() == '/') | - | ||||||||||||
| 281 | || (m_filePath.length() >= 2 | - | ||||||||||||
| 282 | && m_filePath.at(0) == QLatin1Char('/') | - | ||||||||||||
| 283 | && m_filePath.at(1) == QLatin1Char('/'))); | - | ||||||||||||
| 284 | } | - | ||||||||||||
| 285 | #else | - | ||||||||||||
| 286 | bool QFileSystemEntry::isRelative() const | - | ||||||||||||
| 287 | { | - | ||||||||||||
| 288 | return !isAbsolute(); | - | ||||||||||||
| 289 | } | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | bool QFileSystemEntry::isAbsolute() const | - | ||||||||||||
| 292 | { | - | ||||||||||||
| 293 | resolveFilePath(); | - | ||||||||||||
| 294 | return (!m_filePath.isEmpty() && (m_filePath.at(0).unicode() == '/')); | - | ||||||||||||
| 295 | } | - | ||||||||||||
| 296 | #endif | - | ||||||||||||
| 297 | - | |||||||||||||
| 298 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 299 | bool QFileSystemEntry::isDriveRoot() const | - | ||||||||||||
| 300 | { | - | ||||||||||||
| 301 | resolveFilePath(); | - | ||||||||||||
| 302 | #ifndef Q_OS_WINRT | - | ||||||||||||
| 303 | return (m_filePath.length() == 3 | - | ||||||||||||
| 304 | && m_filePath.at(0).isLetter() && m_filePath.at(1) == QLatin1Char(':') | - | ||||||||||||
| 305 | && m_filePath.at(2) == QLatin1Char('/')); | - | ||||||||||||
| 306 | #else // !Q_OS_WINRT | - | ||||||||||||
| 307 | return m_filePath == QDir::rootPath(); | - | ||||||||||||
| 308 | #endif // !Q_OS_WINRT | - | ||||||||||||
| 309 | } | - | ||||||||||||
| 310 | #endif | - | ||||||||||||
| 311 | - | |||||||||||||
| 312 | bool QFileSystemEntry::isRoot() const | - | ||||||||||||
| 313 | { | - | ||||||||||||
| 314 | resolveFilePath(); | - | ||||||||||||
| 315 | if (m_filePath == QLatin1String("/") | - | ||||||||||||
| 316 | #if defined(Q_OS_WIN) | - | ||||||||||||
| 317 | || isDriveRoot() | - | ||||||||||||
| 318 | || isUncRoot(m_filePath) | - | ||||||||||||
| 319 | #endif | - | ||||||||||||
| 320 | ) | - | ||||||||||||
| 321 | return true; | - | ||||||||||||
| 322 | - | |||||||||||||
| 323 | return false; | - | ||||||||||||
| 324 | } | - | ||||||||||||
| 325 | - | |||||||||||||
| 326 | bool QFileSystemEntry::isEmpty() const | - | ||||||||||||
| 327 | { | - | ||||||||||||
| 328 | return m_filePath.isEmpty() && m_nativeFilePath.isEmpty(); | - | ||||||||||||
| 329 | } | - | ||||||||||||
| 330 | - | |||||||||||||
| 331 | // private methods | - | ||||||||||||
| 332 | - | |||||||||||||
| 333 | void QFileSystemEntry::findLastSeparator() const | - | ||||||||||||
| 334 | { | - | ||||||||||||
| 335 | if (m_lastSeparator == -2) { | - | ||||||||||||
| 336 | resolveFilePath(); | - | ||||||||||||
| 337 | m_lastSeparator = m_filePath.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||
| 338 | } | - | ||||||||||||
| 339 | } | - | ||||||||||||
| 340 | - | |||||||||||||
| 341 | void QFileSystemEntry::findFileNameSeparators() const | - | ||||||||||||
| 342 | { | - | ||||||||||||
| 343 | if (m_firstDotInFileName == -2) { | - | ||||||||||||
| 344 | resolveFilePath(); | - | ||||||||||||
| 345 | int firstDotInFileName = -1; | - | ||||||||||||
| 346 | int lastDotInFileName = -1; | - | ||||||||||||
| 347 | int lastSeparator = m_lastSeparator; | - | ||||||||||||
| 348 | - | |||||||||||||
| 349 | int stop; | - | ||||||||||||
| 350 | if (lastSeparator < 0) { | - | ||||||||||||
| 351 | lastSeparator = -1; | - | ||||||||||||
| 352 | stop = 0; | - | ||||||||||||
| 353 | } else { | - | ||||||||||||
| 354 | stop = lastSeparator; | - | ||||||||||||
| 355 | } | - | ||||||||||||
| 356 | - | |||||||||||||
| 357 | int i = m_filePath.size() - 1; | - | ||||||||||||
| 358 | for (; i >= stop; --i) { | - | ||||||||||||
| 359 | if (m_filePath.at(i).unicode() == '.') { | - | ||||||||||||
| 360 | firstDotInFileName = lastDotInFileName = i; | - | ||||||||||||
| 361 | break; | - | ||||||||||||
| 362 | } else if (m_filePath.at(i).unicode() == '/') { | - | ||||||||||||
| 363 | lastSeparator = i; | - | ||||||||||||
| 364 | break; | - | ||||||||||||
| 365 | } | - | ||||||||||||
| 366 | } | - | ||||||||||||
| 367 | - | |||||||||||||
| 368 | if (lastSeparator != i) { | - | ||||||||||||
| 369 | for (--i; i >= stop; --i) { | - | ||||||||||||
| 370 | if (m_filePath.at(i).unicode() == '.') | - | ||||||||||||
| 371 | firstDotInFileName = i; | - | ||||||||||||
| 372 | else if (m_filePath.at(i).unicode() == '/') { | - | ||||||||||||
| 373 | lastSeparator = i; | - | ||||||||||||
| 374 | break; | - | ||||||||||||
| 375 | } | - | ||||||||||||
| 376 | } | - | ||||||||||||
| 377 | } | - | ||||||||||||
| 378 | m_lastSeparator = lastSeparator; | - | ||||||||||||
| 379 | m_firstDotInFileName = firstDotInFileName == -1 ? -1 : firstDotInFileName - qMax(0, lastSeparator); | - | ||||||||||||
| 380 | if (lastDotInFileName == -1) | - | ||||||||||||
| 381 | m_lastDotInFileName = -1; | - | ||||||||||||
| 382 | else if (firstDotInFileName == lastDotInFileName) | - | ||||||||||||
| 383 | m_lastDotInFileName = 0; | - | ||||||||||||
| 384 | else | - | ||||||||||||
| 385 | m_lastDotInFileName = lastDotInFileName - firstDotInFileName; | - | ||||||||||||
| 386 | } | - | ||||||||||||
| 387 | } | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | bool QFileSystemEntry::isClean() const | - | ||||||||||||
| 390 | { | - | ||||||||||||
| 391 | resolveFilePath(); | - | ||||||||||||
| 392 | int dots = 0; | - | ||||||||||||
| 393 | bool dotok = true; // checking for ".." or "." starts to relative paths | - | ||||||||||||
| 394 | bool slashok = true; | - | ||||||||||||
| 395 | for (QString::const_iterator iter = m_filePath.constBegin(); iter != m_filePath.constEnd(); ++iter++)) {
| 18319-748595 | ||||||||||||
| 396 | if (*iter == QLatin1Char('/')) {
| 98093-650502 | ||||||||||||
| 397 | if (dots == 1 || dots == 2)
| 6-98087 | ||||||||||||
| 398 | return false; // path contains "./" or "../" executed 140 times by 6 tests: return false;Executed by:
| 140 | ||||||||||||
| 399 | if (!slashok)
| 2629-95324 | ||||||||||||
| 400 | return false; // path contains "//" executed 2629 times by 30 tests: return false;Executed by:
| 2629 | ||||||||||||
| 401 | dots = 0; | - | ||||||||||||
| 402 | dotok = true; | - | ||||||||||||
| 403 | slashok = false; | - | ||||||||||||
| 404 | } else if (dotok) { executed 95324 times by 156 tests: end of blockExecuted by:
| 95073-555429 | ||||||||||||
| 405 | slashok = true; | - | ||||||||||||
| 406 | if (*iter == QLatin1Char('.')) {
| 3149-91924 | ||||||||||||
| 407 | dots++; | - | ||||||||||||
| 408 | if (dots > 2)
| 1-3148 | ||||||||||||
| 409 | dotok = false; executed 1 time by 1 test: dotok = false;Executed by:
| 1 | ||||||||||||
| 410 | } else { executed 3149 times by 22 tests: end of blockExecuted by:
| 3149 | ||||||||||||
| 411 | //path element contains a character other than '.', it's clean | - | ||||||||||||
| 412 | dots = 0; | - | ||||||||||||
| 413 | dotok = false; | - | ||||||||||||
| 414 | } executed 91924 times by 156 tests: end of blockExecuted by:
| 91924 | ||||||||||||
| 415 | } | - | ||||||||||||
| 416 | } executed 745826 times by 156 tests: end of blockExecuted by:
| 745826 | ||||||||||||
| 417 | return (dots != 1 && dots != 2); // clean if path doesn't end in . or .. executed 18319 times by 156 tests: return (dots != 1 && dots != 2);Executed by:
| 18319 | ||||||||||||
| 418 | } | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |