diff --git a/lib/konq/konq_fileundomanager.cpp b/lib/konq/konq_fileundomanager.cpp index bf12112c06..ffa33b6488 100644 --- a/lib/konq/konq_fileundomanager.cpp +++ b/lib/konq/konq_fileundomanager.cpp @@ -316,7 +316,7 @@ void KonqFileUndoManager::undo() d->m_current = cmd; KonqBasicOperation::Stack& opStack = d->m_current.m_opStack; - assert( !opStack.isEmpty() ); + // Note that opStack is empty for simple operations like MKDIR. // Let's first ask for confirmation if we need to delete any file (#99898) KUrl::List fileCleanupStack; @@ -327,6 +327,9 @@ void KonqFileUndoManager::undo() fileCleanupStack.append( (*it).m_dst ); } } + if ( d->m_current.m_type == KonqFileUndoManager::MKDIR ) { + fileCleanupStack.append(d->m_current.m_dst); + } if ( !fileCleanupStack.isEmpty() ) { if ( !d->m_uiInterface->confirmDeletion( fileCleanupStack ) ) { return; diff --git a/lib/konq/tests/konqfileundomanagertest.cpp b/lib/konq/tests/konqfileundomanagertest.cpp index 0da7cdfad5..74700fd2fa 100644 --- a/lib/konq/tests/konqfileundomanagertest.cpp +++ b/lib/konq/tests/konqfileundomanagertest.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -241,6 +242,7 @@ void KonqFileUndoManagerTest::testCopyFiles() QVERIFY( QFile::exists( destFile() ) ); // nothing happened yet // OK, now do it + m_uiInterface->clear(); m_uiInterface->setNextReplyToConfirmDeletion( true ); doUndo(); @@ -388,6 +390,35 @@ void KonqFileUndoManagerTest::testRenameDir() QVERIFY( !QFileInfo( newUrl.path() ).isDir() ); } +void KonqFileUndoManagerTest::testCreateDir() +{ + const KUrl url( srcSubDir() + ".mkdir" ); + const QString path = url.path(); + QVERIFY( !QFile::exists(path) ); + + KIO::SimpleJob* job = KIO::mkdir(url); + job->setUiDelegate( 0 ); + KonqFileUndoManager::self()->recordJob( KonqFileUndoManager::MKDIR, KUrl(), url, job ); + bool ok = KIO::NetAccess::synchronousRun( job, 0 ); + QVERIFY( ok ); + QVERIFY( QFile::exists(path) ); + QVERIFY( QFileInfo(path).isDir() ); + + m_uiInterface->clear(); + m_uiInterface->setNextReplyToConfirmDeletion( false ); // act like the user didn't confirm + KonqFileUndoManager::self()->undo(); + QCOMPARE( m_uiInterface->files().count(), 1 ); // confirmDeletion was called + QCOMPARE( m_uiInterface->files()[0].url(), url.url() ); + QVERIFY( QFile::exists(path) ); // nothing happened yet + + // OK, now do it + m_uiInterface->clear(); + m_uiInterface->setNextReplyToConfirmDeletion( true ); + doUndo(); + + QVERIFY( !QFile::exists(path) ); +} + void KonqFileUndoManagerTest::testTrashFiles() { if ( !KProtocolInfo::isKnownProtocol( "trash" ) ) diff --git a/lib/konq/tests/konqfileundomanagertest.h b/lib/konq/tests/konqfileundomanagertest.h index adaae27aa1..d71222d524 100644 --- a/lib/konq/tests/konqfileundomanagertest.h +++ b/lib/konq/tests/konqfileundomanagertest.h @@ -38,6 +38,7 @@ private slots: void testRenameDir(); void testTrashFiles(); void testModifyFileBeforeUndo(); // #20532 + void testCreateDir(); // TODO find tests that would lead to kio job errors