summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorCarlos Manuel Duclos Vergara <carlos.duclos@nokia.com>2011-03-30 12:05:03 (GMT)
committerCarlos Manuel Duclos Vergara <carlos.duclos@nokia.com>2011-03-30 12:20:14 (GMT)
commitb3ba4b7de3bac0e444654fe150b4e5b3cc82fb39 (patch)
tree6191316d70bd7a326dd1fd836f45fd20ff53020d /src/corelib/io
parent0cc8a2d09d8dc1d2da87878e70fad0d343b0dcd6 (diff)
downloadQt-b3ba4b7de3bac0e444654fe150b4e5b3cc82fb39.zip
Qt-b3ba4b7de3bac0e444654fe150b4e5b3cc82fb39.tar.gz
Qt-b3ba4b7de3bac0e444654fe150b4e5b3cc82fb39.tar.bz2
QDirIterator returns hidden directories when it should only return files
In Qt 4.5.3 and earlier, creating a QDirIterator with QDir::Files | QDir::Hidden (i.e. search for all files, including hidden files) returned a list of all hidden and non-hidden files in a directory tree. In Qt 4.6.0 and later the same filter causes QDirIterator to return a list of all hidden and non-hidden files and all hidden directories. As the user is asking only for files, clearly returning hidden directories too is incorrect behaviour. Similarly, when asking for QDir::Dirs | QDir::Hidden (i.e. all directories, including hidden directories), hidden files are also (wrongly) returned. Task-number: QTBUG-15421 Reviewed-by: joao
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdiriterator.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index 3b4adc3..4d3f50b 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -278,6 +278,7 @@ void QDirIteratorPrivate::checkAndPushDirectory(const QFileInfo &fileInfo)
current entry will be returned as part of the directory iteration);
otherwise, false is returned.
*/
+
bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInfo &fi) const
{
Q_ASSERT(!fileName.isEmpty());
@@ -312,6 +313,14 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
return false;
}
#endif
+ // skip symlinks
+ const bool skipSymlinks = (filters & QDir::NoSymLinks);
+ const bool includeSystem = (filters & QDir::System);
+ if(skipSymlinks && fi.isSymLink()) {
+ // The only reason to save this file is if it is a broken link and we are requesting system files.
+ if(!includeSystem || fi.exists())
+ return false;
+ }
// filter hidden
const bool includeHidden = (filters & QDir::Hidden);
@@ -319,27 +328,20 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
return false;
// filter system files
- const bool includeSystem = (filters & QDir::System);
- if (!includeSystem && ((!fi.isFile() && !fi.isDir() && !fi.isSymLink())
+ if (!includeSystem && (!(fi.isFile() || fi.isDir() || fi.isSymLink())
|| (!fi.exists() && fi.isSymLink())))
return false;
// skip directories
const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
- if (skipDirs && fi.isDir()) {
- if (!((includeHidden && !dotOrDotDot && fi.isHidden())
- || (includeSystem && !fi.exists() && fi.isSymLink())))
- return false;
- }
+ if (skipDirs && fi.isDir())
+ return false;
// skip files
const bool skipFiles = !(filters & QDir::Files);
- const bool skipSymlinks = (filters & QDir::NoSymLinks);
- if ((skipFiles && (fi.isFile() || !fi.exists())) || (skipSymlinks && fi.isSymLink())) {
- if (!((includeHidden && !dotOrDotDot && fi.isHidden())
- || (includeSystem && !fi.exists() && fi.isSymLink())))
- return false;
- }
+ if (skipFiles && fi.isFile())
+ // Basically we need a reason not to exclude this file otherwise we just eliminate it.
+ return false;
// filter permissions
const bool filterPermissions = ((filters & QDir::PermissionMask)