Comparar commits

...

1 Commits

Autor SHA1 Mensagem Data
Olivier Goffart 3bb364980c FolderWatcher (linux): optimize slotAddFolderRecursive
- Instead of putting all the pathes in a big QStringList and then process them,
  do the processing as we iterate with QDirIterator

- Since we know that the parent directory is not ignored, we can simplify the
  ignore check by not checking the part before (i.e: we call
  ExcludedFiles::isExcluded with the parent 'path' as base path) This is what
  speeds up considerably the function.

Note that the OWNCLOUD_TEST check is already there in FolderWatcher::pathIsIgnored
so the behavior is not changed
2016-10-12 16:56:05 +02:00
5 arquivos alterados com 60 adições e 82 exclusões
+1 -1
Ver Arquivo
@@ -188,7 +188,7 @@ QString Folder::shortGuiLocalPath() const
}
bool Folder::ignoreHiddenFiles()
bool Folder::ignoreHiddenFiles() const
{
bool re(_definition.ignoreHiddenFiles);
return re;
+1 -1
Ver Arquivo
@@ -167,7 +167,7 @@ public:
* Ignore syncing of hidden files or not. This is defined in the
* folder definition
*/
bool ignoreHiddenFiles();
bool ignoreHiddenFiles() const;
void setIgnoreHiddenFiles(bool ignore);
// Used by the Socket API
+35 -53
Ver Arquivo
@@ -23,6 +23,7 @@
#include <QStringList>
#include <QObject>
#include <QVarLengthArray>
#include <syncengine.h>
namespace OCC {
@@ -48,31 +49,6 @@ FolderWatcherPrivate::~FolderWatcherPrivate()
}
// attention: result list passed by reference!
bool FolderWatcherPrivate::findFoldersBelow( const QDir& dir, QStringList& fullList )
{
bool ok = true;
if( !(dir.exists() && dir.isReadable()) ) {
qDebug() << "Non existing path coming in: " << dir.absolutePath();
ok = false;
} else {
QStringList nameFilter;
nameFilter << QLatin1String("*");
QDir::Filters filter = QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::Hidden;
const QStringList pathes = dir.entryList(nameFilter, filter);
QStringList::const_iterator constIterator;
for (constIterator = pathes.constBegin(); constIterator != pathes.constEnd();
++constIterator) {
const QString fullPath(dir.path()+QLatin1String("/")+(*constIterator));
fullList.append(fullPath);
ok = findFoldersBelow(QDir(fullPath), fullList);
}
}
return ok;
}
void FolderWatcherPrivate::inotifyRegisterPath(const QString& path)
{
if( !path.isEmpty()) {
@@ -88,41 +64,47 @@ void FolderWatcherPrivate::inotifyRegisterPath(const QString& path)
void FolderWatcherPrivate::slotAddFolderRecursive(const QString &path)
{
int subdirs = 0;
qDebug() << "(+) Watcher:" << path;
QDir inPath(path);
inotifyRegisterPath(inPath.absolutePath());
const QStringList watchedFolders = _watches.values();
QStringList allSubfolders;
if( !findFoldersBelow(QDir(path), allSubfolders)) {
qDebug() << "Could not traverse all sub folders";
}
// qDebug() << "currently watching " << watchedFolders;
QStringListIterator subfoldersIt(allSubfolders);
while (subfoldersIt.hasNext()) {
QString subfolder = subfoldersIt.next();
// qDebug() << " (**) subfolder: " << subfolder;
QDir folder (subfolder);
if (folder.exists() && !watchedFolders.contains(folder.absolutePath())) {
subdirs++;
if( _parent->pathIsIgnored(subfolder) ) {
qDebug() << "* Not adding" << folder.path();
continue;
}
inotifyRegisterPath(folder.absolutePath());
} else {
qDebug() << " `-> discarded:" << folder.path();
}
}
int subdirs = addFolderRecursiveHelper(path, watchedFolders.toSet());
if (subdirs >0) {
qDebug() << " `-> and" << subdirs << "subdirectories";
}
}
int FolderWatcherPrivate::addFolderRecursiveHelper(const QString &path, const QSet<QString> &watchedFolders)
{
QDir dir(path);
if( !(dir.exists() && dir.isReadable()) ) {
qDebug() << "Non existing path coming in: " << dir.absolutePath();
return 0;
}
int subdirs = 1;
inotifyRegisterPath(dir.absolutePath());
QDir::Filters filter = QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::Hidden;
const QStringList pathes = dir.entryList(filter);
for (auto constIterator = pathes.constBegin(); constIterator != pathes.constEnd(); ++constIterator) {
const QString subfolder = path + QLatin1String("/") + (*constIterator);
QDir folder(subfolder);
if (folder.exists() && !watchedFolders.contains(subfolder)) {
#ifndef OWNCLOUD_TEST // InotifyWatcherTest is not interested in ignored files and does not link against the folder
if( _parent->_folder->syncEngine().excludedFiles().isExcluded(
subfolder, path, _parent->_folder->ignoreHiddenFiles())) {
qDebug() << "* Not adding" << folder.path();
continue;
}
#endif
subdirs += addFolderRecursiveHelper(subfolder, watchedFolders);
} else {
qDebug() << " `-> discarded:" << folder.path();
}
}
return subdirs;
}
void FolderWatcherPrivate::slotReceivedNotification(int fd)
{
int len;
+1 -3
Ver Arquivo
@@ -33,7 +33,6 @@ class FolderWatcherPrivate : public QObject
{
Q_OBJECT
public:
FolderWatcherPrivate() { }
FolderWatcherPrivate(FolderWatcher *p, const QString &path);
~FolderWatcherPrivate();
@@ -45,10 +44,9 @@ protected slots:
void slotAddFolderRecursive(const QString &path);
protected:
bool findFoldersBelow( const QDir& dir, QStringList& fullList );
int addFolderRecursiveHelper(const QString &path, const QSet<QString> &watchedFolders);
void inotifyRegisterPath(const QString& path);
private:
FolderWatcher *_parent;
QString _folder;
+22 -24
Ver Arquivo
@@ -11,18 +11,23 @@
using namespace OCC;
class TestInotifyWatcher: public FolderWatcherPrivate
struct FriendlyFolderWatcherPrivate : FolderWatcherPrivate
{
using FolderWatcherPrivate::FolderWatcherPrivate;
friend class TestInotifyWatcher;
};
class TestInotifyWatcher : public QObject
{
Q_OBJECT
private:
QString _root;
private slots:
void initTestCase() {
qsrand(QTime::currentTime().msec());
// Test the recursive path listing function lists everything
void testAddFolderRecursiveHelper() {
QTemporaryDir tmpDir;
_root = QDir::tempPath() + "/" + "test_" + QString::number(qrand());
QString _root = tmpDir.path();
qDebug() << "creating test directory tree in " << _root;
QDir rootDir(_root);
@@ -32,13 +37,13 @@ private slots:
rootDir.mkpath(_root + "/a1/b3/c3");
rootDir.mkpath(_root + "/a2/b3/c3");
}
FriendlyFolderWatcherPrivate watcher(0, _root);
QVERIFY(watcher._fd >= 0);
QCoreApplication::processEvents(); // Let the slotAddFolderRecursive slot run;
QStringList dirs = watcher._watches.values();
// Test the recursive path listing function findFoldersBelow
void testDirsBelowPath() {
QStringList dirs;
QVERIFY( dirs.indexOf(_root)>-1);
bool ok = findFoldersBelow(QDir(_root), dirs);
QVERIFY( dirs.indexOf(_root + "/a1")>-1);
QVERIFY( dirs.indexOf(_root + "/a1/b1")>-1);
QVERIFY( dirs.indexOf(_root + "/a1/b1/c1")>-1);
@@ -53,20 +58,13 @@ private slots:
QVERIFY( dirs.indexOf(_root + "/a1/b3")>-1);
QVERIFY( dirs.indexOf(_root + "/a1/b3/c3")>-1);
QVERIFY( dirs.indexOf(_root + "/a2"));
QVERIFY( dirs.indexOf(_root + "/a2/b3"));
QVERIFY( dirs.indexOf(_root + "/a2/b3/c3"));
QVERIFY( dirs.contains(_root + "/a2"));
QVERIFY( dirs.contains(_root + "/a2/b3"));
QVERIFY( dirs.contains(_root + "/a2/b3/c3"));
QVERIFY2(dirs.count() == 11, "Directory count wrong.");
QVERIFY2(ok, "findFoldersBelow failed.");
QCOMPARE(dirs.count(), 12);
}
void cleanupTestCase() {
if( _root.startsWith(QDir::tempPath() )) {
system( QString("rm -rf %1").arg(_root).toLocal8Bit() );
}
}
};
QTEST_APPLESS_MAIN(TestInotifyWatcher)