Commit 74b0d33a authored by David Faure's avatar David Faure

Fix dirwatching being stopped when using KIO::moveAs().

CopyJob calls stopDirScan to avoid notification storm (it uses KDirNotify
i.e. DBus to notify of the operation instead), and forgot to call
restartDirScan in the precise case of direct renaming. Moving a '}' fixed it.

With many thanks to Frank Reininghaus for another great unittest!

BUG: 311582
FIXED-IN: 4.10
parent 82a32a77
......@@ -1746,6 +1746,7 @@ void CopyJob::emitResult()
// Even if some error made us abort midway, we might still have done
// part of the job so we better update the views! (#118583)
if (!d->m_bOnlyRenames) {
// If only renaming happened, KDirNotify::FileRenamed was emitted by the rename jobs
KUrl url(d->m_globalDest);
if (d->m_globalDestinationState != DEST_IS_DIR || d->m_asMethod)
url.setPath(url.directory());
......@@ -1756,12 +1757,12 @@ void CopyJob::emitResult()
kDebug(7007) << "KDirNotify'ing FilesRemoved" << d->m_successSrcList.toStringList();
org::kde::KDirNotify::emitFilesRemoved(d->m_successSrcList.toStringList());
}
}
// Re-enable watching on the dirs that held the deleted files
if (d->m_mode == CopyJob::Move) {
for (QSet<QString>::const_iterator it = d->m_parentDirs.constBegin() ; it != d->m_parentDirs.constEnd() ; ++it)
KDirWatch::self()->restartDirScan( *it );
}
// Re-enable watching on the dirs that held the deleted/moved files
if (d->m_mode == CopyJob::Move) {
for (QSet<QString>::const_iterator it = d->m_parentDirs.constBegin() ; it != d->m_parentDirs.constEnd() ; ++it)
KDirWatch::self()->restartDirScan( *it );
}
Job::emitResult();
}
......
......@@ -1000,6 +1000,62 @@ void KDirListerTest::testRedirection()
}
void KDirListerTest::testWatchingAfterCopyJob() // #331582
{
m_items.clear();
KTempDir newDir;
const QString path = newDir.name();
// List and watch an empty dir
connect(&m_dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(slotNewItems(KFileItemList)));
m_dirLister.openUrl(KUrl(path));
QVERIFY(QTest::kWaitForSignal(&m_dirLister, SIGNAL(completed()), 1000));
QVERIFY(m_dirLister.isFinished());
QVERIFY(m_items.isEmpty());
// Create three subfolders.
QVERIFY(QDir().mkdir(path + "New Folder"));
QVERIFY(QDir().mkdir(path + "New Folder 1"));
QVERIFY(QDir().mkdir(path + "New Folder 2"));
QVERIFY(QTest::kWaitForSignal(&m_dirLister, SIGNAL(completed()), 1000));
QVERIFY(m_dirLister.isFinished());
QCOMPARE(m_items.count(), 3);
// Create a new file and verify that the dir lister notices it.
m_items.clear();
createTestFile(path + "a");
QVERIFY(QTest::kWaitForSignal(&m_dirLister, SIGNAL(completed()), 1000));
QVERIFY(m_dirLister.isFinished());
QCOMPARE(m_items.count(), 1);
// Rename one of the subfolders.
const QString oldPath = path + "New Folder 1";
const QString newPath = path + "New Folder 1a";
// NOTE: The following two lines are required to trigger the bug!
KIO::Job* job = KIO::moveAs(KUrl(oldPath), KUrl(newPath), KIO::HideProgressInfo);
job->exec();
// Now try to create a second new file in and verify that the
// dir lister notices it.
m_items.clear();
createTestFile(path + "b");
int numTries = 0;
// Give time for KDirWatch to notify us
// This should end up in "KDirListerCache::slotFileDirty"
while (m_items.isEmpty()) {
QVERIFY(++numTries < 10);
QTest::qWait(200);
}
QCOMPARE(m_items.count(), 1);
newDir.unlink();
QVERIFY(QTest::kWaitForSignal(&m_dirLister, SIGNAL(clear()), 1000));
}
void KDirListerTest::enterLoop(int exitCount)
{
//qDebug("enterLoop");
......
......@@ -109,6 +109,7 @@ private Q_SLOTS:
void testBug211472();
void testRenameCurrentDir();
void testRedirection();
void testWatchingAfterCopyJob();
void testDeleteCurrentDir(); // must be last!
protected Q_SLOTS: // 'more private than private slots' - i.e. not seen by qtestlib
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment