Bug 273802

Summary: "Prune selection" deletes ALL project files without even asking the user if he wants to.
Product: [Applications] kdevelop Reporter: Barade <barade.barade>
Component: Build tools: CMakeAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: critical CC: aleixpol, barade.barade
Priority: NOR    
Version: 2.2   
Target Milestone: 4.2.0   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:

Description Barade 2011-05-21 17:16:47 UTC
Version:           2.2 (using KDE 4.6.2) 
OS:                Linux

I clicked on the "Prune Selection" action and it deleted my whole project on my local computer (all sub directories etc.) without event showing a message box to confirm or something similar.
I don't know if that is "Prune Selection"'s usual behaviour (completely useless in my opinion, I thought it would be clean up the project more comprehensive (deleting CMake cache files etc) but you could at least show some kind of dialog before executing this action.

Reproducible: Didn't try




OS: Linux (i686) release 2.6.36-gentoo-r5
Compiler: i686-pc-linux-gnu-gcc
Comment 1 Barade 2011-05-22 13:20:23 UTC
Found corresponding code lines:
KJob* CMakeBuilder::prune( KDevelop::IProject* project )
{
    KUrl builddir = CMake::currentBuildDir( project );
    if( builddir.isEmpty() )
    {
        KMessageBox::information(KDevelop::ICore::self()->uiController()->activeMainWindow(),
                                 i18n("No Build Directory configured, cannot clear builddir"), i18n("No clearing of builddir possible") );
        return 0;
    }
    QDir d( builddir.toLocalFile() );
    KUrl::List urls;
    foreach( const QString& entry, d.entryList( QDir::NoDotAndDotDot | QDir::AllEntries ) )
    {
        KUrl tmp = builddir;
        tmp.addPath( entry );
        urls << tmp;
    }
    return KIO::del( urls );
} 

In my opinion that is really horrible code. You should at least ask user for confirmation and maybe add some checks if URLs are temporary files and do not belong to the project since in my case I had selected my project folder as build directory.
Comment 2 Milian Wolff 2011-05-27 17:42:23 UTC
I assume you did not use an out-of-source build directory? indeed, there this is very dangerous.

Aleix?
Comment 3 Aleix Pol 2011-05-27 17:48:48 UTC
My only code here is the one checking there actually is a build directory configured...

And yes, that's pretty dangerous (I still think we shouldn't let the user have a in-source builddir in KDevelop).

I'll add a check to see if there is a CMakeLists.txt file then don't remove, but I'm not sure there can be some corner case where this can't be enough...
Comment 4 Aleix Pol 2011-05-27 18:15:20 UTC
Git commit b389cfb2e620abe089d4a86f2315503d6d95196f by Aleix Pol.
Committed on 27/05/2011 at 19:13.
Pushed by apol into branch '4.2'.

Don't clean the build directory if it's a source dir.

BUG: 273802

M  +6    -0    projectbuilders/cmakebuilder/cmakebuilder.cpp     

http://commits.kde.org/kdevelop/b389cfb2e620abe089d4a86f2315503d6d95196f