Skip to content

Commit

Permalink
Fixed Issue nextcloud#1000 - Subfolders of moved folders not synced
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Sterner <joshua.s.sterner@gmail.com>
  • Loading branch information
joshua-sterner committed May 9, 2019
1 parent 2d3bac4 commit b6ff17c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/gui/folderwatcher.cpp
Expand Up @@ -75,9 +75,27 @@ bool FolderWatcher::isReliable() const
return _isReliable;
}

void FolderWatcher::appendSubPaths(QDir dir, QStringList& subPaths) {
QStringList newSubPaths = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
for (int i = 0; i < newSubPaths.size(); i++) {
QString path = dir.path() + "/" + newSubPaths[i];
QFileInfo fileInfo(path);
subPaths.append(path);
if (fileInfo.isDir()) {
QDir dir(path);
appendSubPaths(dir, subPaths);
}
}
}

void FolderWatcher::changeDetected(const QString &path)
{
QFileInfo fileInfo(path);
QStringList paths(path);
if (fileInfo.isDir()) {
QDir dir(path);
appendSubPaths(dir, paths);
}
changeDetected(paths);
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/folderwatcher.h
Expand Up @@ -26,6 +26,7 @@
#include <QHash>
#include <QScopedPointer>
#include <QSet>
#include <QDir>

class QTimer;

Expand Down Expand Up @@ -120,6 +121,8 @@ protected slots:
Folder *_folder;
bool _isReliable = true;

void appendSubPaths(QDir dir, QStringList& subPaths);

friend class FolderWatcherPrivate;
};
}
Expand Down
13 changes: 13 additions & 0 deletions test/testfolderwatcher.cpp
Expand Up @@ -140,6 +140,19 @@ private slots:
QVERIFY(waitForPathChanged(file));
}

void testMove3LevelDirWithFile() {
QString file(_rootPath + "/a0/b/c/empty.txt");
mkdir(_rootPath + "/a0");
mkdir(_rootPath + "/a0/b");
mkdir(_rootPath + "/a0/b/c");
touch(file);
QString cmd = QString("mv " + _rootPath + "/a0 " + _rootPath + "/a");
qDebug() << "Command: " << cmd;
system(cmd.toLocal8Bit());
QVERIFY(waitForPathChanged(_rootPath + "/a/b/c/empty.txt"));
}


void testCreateADir() {
QString file(_rootPath+"/a1/b1/new_dir");
mkdir(file);
Expand Down

0 comments on commit b6ff17c

Please sign in to comment.