Fix assert when doing undo after a mkdir.

Show confirmation before deleting the directory (the user might have put files into it using the command line for instance!).

svn path=/trunk/KDE/kdebase/apps/; revision=764395
This commit is contained in:
David Faure 2008-01-21 17:10:46 +00:00
parent 1425d83528
commit 64afc9bb24
3 changed files with 36 additions and 1 deletions

View file

@ -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;

View file

@ -23,6 +23,7 @@
#include <konq_fileundomanager.h>
#include <kio/copyjob.h>
#include <kio/job.h>
#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <kprotocolinfo.h>
@ -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" ) )

View file

@ -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