Comparar commits
1 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 3bb364980c |
@@ -188,7 +188,7 @@ QString Folder::shortGuiLocalPath() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Folder::ignoreHiddenFiles()
|
bool Folder::ignoreHiddenFiles() const
|
||||||
{
|
{
|
||||||
bool re(_definition.ignoreHiddenFiles);
|
bool re(_definition.ignoreHiddenFiles);
|
||||||
return re;
|
return re;
|
||||||
|
|||||||
+1
-1
@@ -167,7 +167,7 @@ public:
|
|||||||
* Ignore syncing of hidden files or not. This is defined in the
|
* Ignore syncing of hidden files or not. This is defined in the
|
||||||
* folder definition
|
* folder definition
|
||||||
*/
|
*/
|
||||||
bool ignoreHiddenFiles();
|
bool ignoreHiddenFiles() const;
|
||||||
void setIgnoreHiddenFiles(bool ignore);
|
void setIgnoreHiddenFiles(bool ignore);
|
||||||
|
|
||||||
// Used by the Socket API
|
// Used by the Socket API
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVarLengthArray>
|
#include <QVarLengthArray>
|
||||||
|
#include <syncengine.h>
|
||||||
|
|
||||||
namespace OCC {
|
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)
|
void FolderWatcherPrivate::inotifyRegisterPath(const QString& path)
|
||||||
{
|
{
|
||||||
if( !path.isEmpty()) {
|
if( !path.isEmpty()) {
|
||||||
@@ -88,41 +64,47 @@ void FolderWatcherPrivate::inotifyRegisterPath(const QString& path)
|
|||||||
|
|
||||||
void FolderWatcherPrivate::slotAddFolderRecursive(const QString &path)
|
void FolderWatcherPrivate::slotAddFolderRecursive(const QString &path)
|
||||||
{
|
{
|
||||||
int subdirs = 0;
|
|
||||||
qDebug() << "(+) Watcher:" << path;
|
qDebug() << "(+) Watcher:" << path;
|
||||||
|
|
||||||
QDir inPath(path);
|
|
||||||
inotifyRegisterPath(inPath.absolutePath());
|
|
||||||
|
|
||||||
const QStringList watchedFolders = _watches.values();
|
const QStringList watchedFolders = _watches.values();
|
||||||
|
int subdirs = addFolderRecursiveHelper(path, watchedFolders.toSet());
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subdirs >0) {
|
if (subdirs >0) {
|
||||||
qDebug() << " `-> and" << subdirs << "subdirectories";
|
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)
|
void FolderWatcherPrivate::slotReceivedNotification(int fd)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class FolderWatcherPrivate : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FolderWatcherPrivate() { }
|
|
||||||
FolderWatcherPrivate(FolderWatcher *p, const QString &path);
|
FolderWatcherPrivate(FolderWatcher *p, const QString &path);
|
||||||
~FolderWatcherPrivate();
|
~FolderWatcherPrivate();
|
||||||
|
|
||||||
@@ -45,10 +44,9 @@ protected slots:
|
|||||||
void slotAddFolderRecursive(const QString &path);
|
void slotAddFolderRecursive(const QString &path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool findFoldersBelow( const QDir& dir, QStringList& fullList );
|
int addFolderRecursiveHelper(const QString &path, const QSet<QString> &watchedFolders);
|
||||||
void inotifyRegisterPath(const QString& path);
|
void inotifyRegisterPath(const QString& path);
|
||||||
|
|
||||||
private:
|
|
||||||
FolderWatcher *_parent;
|
FolderWatcher *_parent;
|
||||||
|
|
||||||
QString _folder;
|
QString _folder;
|
||||||
|
|||||||
@@ -11,18 +11,23 @@
|
|||||||
|
|
||||||
using namespace OCC;
|
using namespace OCC;
|
||||||
|
|
||||||
class TestInotifyWatcher: public FolderWatcherPrivate
|
|
||||||
|
struct FriendlyFolderWatcherPrivate : FolderWatcherPrivate
|
||||||
|
{
|
||||||
|
using FolderWatcherPrivate::FolderWatcherPrivate;
|
||||||
|
friend class TestInotifyWatcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TestInotifyWatcher : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
|
||||||
QString _root;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase() {
|
// Test the recursive path listing function lists everything
|
||||||
qsrand(QTime::currentTime().msec());
|
void testAddFolderRecursiveHelper() {
|
||||||
|
QTemporaryDir tmpDir;
|
||||||
|
|
||||||
_root = QDir::tempPath() + "/" + "test_" + QString::number(qrand());
|
QString _root = tmpDir.path();
|
||||||
qDebug() << "creating test directory tree in " << _root;
|
qDebug() << "creating test directory tree in " << _root;
|
||||||
QDir rootDir(_root);
|
QDir rootDir(_root);
|
||||||
|
|
||||||
@@ -32,13 +37,13 @@ private slots:
|
|||||||
rootDir.mkpath(_root + "/a1/b3/c3");
|
rootDir.mkpath(_root + "/a1/b3/c3");
|
||||||
rootDir.mkpath(_root + "/a2/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
|
QVERIFY( dirs.indexOf(_root)>-1);
|
||||||
void testDirsBelowPath() {
|
|
||||||
QStringList dirs;
|
|
||||||
|
|
||||||
bool ok = findFoldersBelow(QDir(_root), dirs);
|
|
||||||
QVERIFY( dirs.indexOf(_root + "/a1")>-1);
|
QVERIFY( dirs.indexOf(_root + "/a1")>-1);
|
||||||
QVERIFY( dirs.indexOf(_root + "/a1/b1")>-1);
|
QVERIFY( dirs.indexOf(_root + "/a1/b1")>-1);
|
||||||
QVERIFY( dirs.indexOf(_root + "/a1/b1/c1")>-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")>-1);
|
||||||
QVERIFY( dirs.indexOf(_root + "/a1/b3/c3")>-1);
|
QVERIFY( dirs.indexOf(_root + "/a1/b3/c3")>-1);
|
||||||
|
|
||||||
QVERIFY( dirs.indexOf(_root + "/a2"));
|
QVERIFY( dirs.contains(_root + "/a2"));
|
||||||
QVERIFY( dirs.indexOf(_root + "/a2/b3"));
|
QVERIFY( dirs.contains(_root + "/a2/b3"));
|
||||||
QVERIFY( dirs.indexOf(_root + "/a2/b3/c3"));
|
QVERIFY( dirs.contains(_root + "/a2/b3/c3"));
|
||||||
|
|
||||||
QVERIFY2(dirs.count() == 11, "Directory count wrong.");
|
QCOMPARE(dirs.count(), 12);
|
||||||
|
|
||||||
QVERIFY2(ok, "findFoldersBelow failed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupTestCase() {
|
|
||||||
if( _root.startsWith(QDir::tempPath() )) {
|
|
||||||
system( QString("rm -rf %1").arg(_root).toLocal8Bit() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(TestInotifyWatcher)
|
QTEST_APPLESS_MAIN(TestInotifyWatcher)
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário