Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.61 KB | None | 0 0
  1. From b1db31d42929b57db8cd57ad58967981a6b3aca1 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  3. Date: Thu, 11 Aug 2011 15:49:37 +0200
  4. Subject: [PATCH 1/7] Fix QDir::operator==(const QDir &) const
  5.  
  6. We can't rely on absolute paths when comparing directories for equality
  7. as these don't take into account symbolic links and may also bypass ../
  8. and ./ simplification.
  9.  
  10. Instead, canonical paths must be computed and can then be compared
  11. according to the case sensitivity rules for the platform or file engine,
  12. as is done in QFileInfo.
  13.  
  14. Task-number: QTBUG-20495
  15. Reviewed-by: ?
  16. ---
  17. src/corelib/io/qdir.cpp      |    6 +++---
  18.  src/corelib/io/qfileinfo.cpp |    1 +
  19.  tests/auto/qdir/tst_qdir.cpp |    6 ++++++
  20.  3 files changed, 10 insertions(+), 3 deletions(-)
  21.  
  22. diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
  23. index f9196e0..6e25d91 100644
  24. --- a/src/corelib/io/qdir.cpp
  25. +++ b/src/corelib/io/qdir.cpp
  26. @@ -1633,9 +1633,9 @@ bool QDir::operator==(const QDir &dir) const
  27.      if (d->filters == other->filters
  28.         && d->sort == other->sort
  29.         && d->nameFilters == other->nameFilters) {
  30. -        d->resolveAbsoluteEntry();
  31. -        other->resolveAbsoluteEntry();
  32. -        return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
  33. +
  34. +        // Fallback to expensive canonical path computation
  35. +        return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
  36.      }
  37.      return false;
  38.  }
  39. diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
  40. index ca42c87..6e25206 100644
  41. --- a/src/corelib/io/qfileinfo.cpp
  42. +++ b/src/corelib/io/qfileinfo.cpp
  43. @@ -406,6 +406,7 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
  44.      if (fileinfo.size() != size()) //if the size isn't the same...
  45.          return false;
  46.  
  47. +   // Fallback to expensive canonical path computation
  48.     return canonicalFilePath().compare(fileinfo.canonicalFilePath(), sensitive) == 0;
  49.  }
  50.  
  51. diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp
  52. index 0a42a97..419eaae 100644
  53. --- a/tests/auto/qdir/tst_qdir.cpp
  54. +++ b/tests/auto/qdir/tst_qdir.cpp
  55. @@ -444,9 +444,15 @@ void tst_QDir::QDir_default()
  56.  void tst_QDir::compare()
  57.  {
  58.      // operator==
  59. +
  60. +    // Not using QCOMPARE to test result of QDir::operator==
  61. +
  62.      QDir dir;
  63.      dir.makeAbsolute();
  64.      QVERIFY(dir == QDir::currentPath());
  65. +
  66. +    QVERIFY(QDir() == QDir(QDir::currentPath()));
  67. +    QVERIFY(QDir("../") == QDir(QDir::currentPath() + "/.."));
  68.  }
  69.  
  70.  static QStringList filterLinks(const QStringList &list)
  71. --
  72. 1.7.5.2
  73.  
  74.  
  75. From 5c3b2bc3a054e285f4a8a9ae986f524319a66f07 Mon Sep 17 00:00:00 2001
  76. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  77. Date: Thu, 11 Aug 2011 16:17:40 +0200
  78. Subject: [PATCH 2/7] Compare non-canonical paths before falling back on
  79.  expensive computation
  80.  
  81. Reviewed-by: ?
  82. ---
  83. src/corelib/io/qdir.cpp      |    4 ++++
  84.  src/corelib/io/qfileinfo.cpp |    5 +++++
  85.  2 files changed, 9 insertions(+), 0 deletions(-)
  86.  
  87. diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
  88. index 6e25d91..c0c62e1 100644
  89. --- a/src/corelib/io/qdir.cpp
  90. +++ b/src/corelib/io/qdir.cpp
  91. @@ -1634,6 +1634,10 @@ bool QDir::operator==(const QDir &dir) const
  92.         && d->sort == other->sort
  93.         && d->nameFilters == other->nameFilters) {
  94.  
  95. +        // Assume directories are the same if path is the same
  96. +        if (d->dirEntry.filePath() == other->dirEntry.filePath())
  97. +            return true;
  98. +
  99.          // Fallback to expensive canonical path computation
  100.          return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
  101.      }
  102. diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
  103. index 6e25206..ff328da 100644
  104. --- a/src/corelib/io/qfileinfo.cpp
  105. +++ b/src/corelib/io/qfileinfo.cpp
  106. @@ -391,6 +391,11 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
  107.          return true;
  108.      if (d->isDefaultConstructed || fileinfo.d_ptr->isDefaultConstructed)
  109.          return false;
  110. +
  111. +    // Assume files are the same if path is the same
  112. +    if (d->fileEntry.filePath() == fileinfo.d_ptr->fileEntry.filePath())
  113. +        return true;
  114. +
  115.      Qt::CaseSensitivity sensitive;
  116.      if (d->fileEngine == 0 || fileinfo.d_ptr->fileEngine == 0) {
  117.          if (d->fileEngine != fileinfo.d_ptr->fileEngine) // one is native, the other is a custom file-engine
  118. --
  119. 1.7.5.2
  120.  
  121.  
  122. From bac33402a448d88b10402aac71846047be14b749 Mon Sep 17 00:00:00 2001
  123. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  124. Date: Fri, 26 Aug 2011 10:39:52 +0200
  125. Subject: [PATCH 3/7] Don't second-guess the "engine"; call cleanPath on
  126.  absolutePaths
  127.  
  128. This ensures there is a single definition of what constitutes an
  129. absolute path in Qt.
  130.  
  131. Task-number: QTBUG-19995
  132. Reviewed-by: ?
  133. ---
  134. src/corelib/io/qdir.cpp |   10 ++--------
  135.  1 files changed, 2 insertions(+), 8 deletions(-)
  136.  
  137. diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
  138. index c0c62e1..cbe635f 100644
  139. --- a/src/corelib/io/qdir.cpp
  140. +++ b/src/corelib/io/qdir.cpp
  141. @@ -197,16 +197,10 @@ inline void QDirPrivate::resolveAbsoluteEntry() const
  142.          return;
  143.  
  144.      QString absoluteName;
  145. -    if (fileEngine.isNull()) {
  146. -        if (!dirEntry.isRelative()) {
  147. -            absoluteDirEntry = dirEntry;
  148. -            return;
  149. -        }
  150. -
  151. +    if (fileEngine.isNull())
  152.          absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath();
  153. -    } else {
  154. +    else
  155.          absoluteName = fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
  156. -    }
  157.  
  158.      absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(absoluteName), QFileSystemEntry::FromInternalPath());
  159.  }
  160. --
  161. 1.7.5.2
  162.  
  163.  
  164. From e139c29265056ce15b69e5d1bc6a7ee82e2df1db Mon Sep 17 00:00:00 2001
  165. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  166. Date: Fri, 26 Aug 2011 11:03:55 +0200
  167. Subject: [PATCH 4/7] We prefer capitalized drive letters, make it so sooner
  168.  
  169. Reviewed-by: ?
  170. ---
  171. src/corelib/io/qfilesystemengine_win.cpp |    5 +++--
  172.  1 files changed, 3 insertions(+), 2 deletions(-)
  173.  
  174. diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
  175. index f704fc3..993c946 100644
  176. --- a/src/corelib/io/qfilesystemengine_win.cpp
  177. +++ b/src/corelib/io/qfilesystemengine_win.cpp
  178. @@ -1052,11 +1052,12 @@ QString QFileSystemEngine::tempPath()
  179.      }
  180.      if (ret.isEmpty()) {
  181.  #if !defined(Q_OS_WINCE)
  182. -        ret = QLatin1String("c:/tmp");
  183. +        ret = QLatin1String("C:/tmp");
  184.  #else
  185.          ret = QLatin1String("/Temp");
  186.  #endif
  187. -    }
  188. +    } else if (ret.length() >= 2 && ret[1] == QLatin1Char(':'))
  189. +        ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters.
  190.      return ret;
  191.  }
  192.  
  193. --
  194. 1.7.5.2
  195.  
  196.  
  197. From b84e73151207801585b3248b8e9312bd75b71952 Mon Sep 17 00:00:00 2001
  198. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  199. Date: Fri, 26 Aug 2011 11:01:48 +0200
  200. Subject: [PATCH 5/7] ret is an "internal" path, no need to re-process it
  201.  
  202. Where "internal" means that it uses Qt's separator '/', regardless of
  203. the native one.
  204. ---
  205. src/corelib/io/qfilesystemengine_win.cpp |    2 +-
  206.  1 files changed, 1 insertions(+), 1 deletions(-)
  207.  
  208. diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
  209. index 993c946..764ee6d 100644
  210. --- a/src/corelib/io/qfilesystemengine_win.cpp
  211. +++ b/src/corelib/io/qfilesystemengine_win.cpp
  212. @@ -536,7 +536,7 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
  213.          // Force uppercase drive letters.
  214.          ret[0] = ret.at(0).toUpper();
  215.      }
  216. -    return QFileSystemEntry(ret);
  217. +    return QFileSystemEntry(ret, QFileSystemEntry::FromInternalPath());
  218.  }
  219.  
  220.  //static
  221. --
  222. 1.7.5.2
  223.  
  224.  
  225. From f804fc8a4427f56929b8a7acaa3aa4cefa5bbc14 Mon Sep 17 00:00:00 2001
  226. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  227. Date: Thu, 11 Aug 2011 18:53:04 +0200
  228. Subject: [PATCH 6/7] Avoid allocations in determining whether path is UNC
  229.  root
  230.  
  231. This function is called from only one place and the path argument is
  232. known to contain non-native separators ('/'). We can make use of this
  233. information, instead of converting the path, thus avoiding allocations.
  234.  
  235. (Is the trimmed() part even necessary?)
  236.  
  237. Reviewed-by: ?
  238. ---
  239. src/corelib/io/qfilesystementry.cpp |   19 ++++++++++++-------
  240.  1 files changed, 12 insertions(+), 7 deletions(-)
  241.  
  242. diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp
  243. index bb7cb4e..3c76186 100644
  244. --- a/src/corelib/io/qfilesystementry.cpp
  245. +++ b/src/corelib/io/qfilesystementry.cpp
  246. @@ -51,18 +51,23 @@
  247.  QT_BEGIN_NAMESPACE
  248.  
  249.  #ifdef Q_OS_WIN
  250. -static bool isUncRoot(const QString &server)
  251. +static inline bool isUncRoot(const QString &server)
  252.  {
  253. -    QString localPath = QDir::toNativeSeparators(server);
  254. -    if (!localPath.startsWith(QLatin1String("\\\\")))
  255. +    if (!server.startsWith(QLatin1String("//")))
  256.          return false;
  257.  
  258. -    int idx = localPath.indexOf(QLatin1Char('\\'), 2);
  259. -    if (idx == -1 || idx + 1 == localPath.length())
  260. +    int idx = server.indexOf(QLatin1Char('/'), 2);
  261. +    if (idx == -1 || idx + 1 == server.length())
  262.          return true;
  263.  
  264. -    localPath = localPath.right(localPath.length() - idx - 1).trimmed();
  265. -    return localPath.isEmpty();
  266. +    // server.mid(idx + 1).trimmed().isEmpty()
  267. +    const QChar *data = server.data();
  268. +
  269. +    while (++idx < server.length()) {
  270. +        if (!data[idx].isSpace())
  271. +            return false;
  272. +    }
  273. +    return true;
  274.  }
  275.  
  276.  static inline QString fixIfRelativeUncPath(const QString &path)
  277. --
  278. 1.7.5.2
  279.  
  280.  
  281. From d6e5db5df36714c61468183c1863f6654d12dcda Mon Sep 17 00:00:00 2001
  282. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  283. Date: Fri, 12 Aug 2011 09:59:41 +0200
  284. Subject: [PATCH 7/7] Don't trim paths in deciding isUncRoot
  285.  
  286. Call to QString::trimmed was introduced (technically, kept) in commit
  287. d851374c7894ac62367d885e7c24650d8635d2e8, when inlining QString::split.
  288. In practice, though, we never trim paths at this point in the API and we
  289. shouldn't.
  290.  
  291. Reviewed-by: ?
  292. ---
  293. src/corelib/io/qfilesystementry.cpp |   12 +-----------
  294.  1 files changed, 1 insertions(+), 11 deletions(-)
  295.  
  296. diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp
  297. index 3c76186..2248787 100644
  298. --- a/src/corelib/io/qfilesystementry.cpp
  299. +++ b/src/corelib/io/qfilesystementry.cpp
  300. @@ -57,17 +57,7 @@ static inline bool isUncRoot(const QString &server)
  301.          return false;
  302.  
  303.      int idx = server.indexOf(QLatin1Char('/'), 2);
  304. -    if (idx == -1 || idx + 1 == server.length())
  305. -        return true;
  306. -
  307. -    // server.mid(idx + 1).trimmed().isEmpty()
  308. -    const QChar *data = server.data();
  309. -
  310. -    while (++idx < server.length()) {
  311. -        if (!data[idx].isSpace())
  312. -            return false;
  313. -    }
  314. -    return true;
  315. +    return (idx == -1 || idx + 1 == server.length())
  316.  }
  317.  
  318.  static inline QString fixIfRelativeUncPath(const QString &path)
  319. --
  320. 1.7.5.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement