2015-02-27 19:07:17 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ClearTempMountsJob.h"
|
|
|
|
|
|
|
|
#include <util/report.h>
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
|
|
ClearTempMountsJob::ClearTempMountsJob()
|
|
|
|
: Calamares::Job()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ClearTempMountsJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Clear all temporary mounts." );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-13 02:24:58 +02:00
|
|
|
QString
|
|
|
|
ClearTempMountsJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Clearing all temporary mounts." );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-27 19:07:17 +01:00
|
|
|
Calamares::JobResult
|
|
|
|
ClearTempMountsJob::exec()
|
|
|
|
{
|
|
|
|
// Fetch a list of current mounts to Calamares temporary directories.
|
2015-02-27 20:43:21 +01:00
|
|
|
QList< QPair < QString, QString > > lst;
|
2015-02-27 19:07:17 +01:00
|
|
|
QFile mtab( "/etc/mtab" );
|
|
|
|
if ( !mtab.open( QFile::ReadOnly | QFile::Text ) )
|
|
|
|
return Calamares::JobResult::error( tr( "Cannot get list of temporary mounts." ) );
|
|
|
|
|
2015-02-27 20:31:17 +01:00
|
|
|
cDebug() << "Opened mtab. Lines:";
|
2015-02-28 16:44:09 +01:00
|
|
|
QTextStream in(&mtab);
|
|
|
|
QString lineIn = in.readLine();
|
|
|
|
while ( !lineIn.isNull() )
|
2015-02-27 19:07:17 +01:00
|
|
|
{
|
2015-02-28 16:44:09 +01:00
|
|
|
QStringList line = lineIn.split( ' ', QString::SkipEmptyParts );
|
2015-02-27 20:31:17 +01:00
|
|
|
cDebug() << line.join( ' ' );
|
2015-02-27 19:07:17 +01:00
|
|
|
QString device = line.at( 0 );
|
|
|
|
QString mountPoint = line.at( 1 );
|
|
|
|
if ( mountPoint.startsWith( "/tmp/calamares-" ) )
|
2015-02-27 20:31:17 +01:00
|
|
|
{
|
|
|
|
cDebug() << "INSERTING pair (device, mountPoint)" << device << mountPoint;
|
2015-02-27 20:43:21 +01:00
|
|
|
lst.append( qMakePair( device, mountPoint ) );
|
2015-02-27 20:31:17 +01:00
|
|
|
}
|
2015-02-28 16:44:09 +01:00
|
|
|
lineIn = in.readLine();
|
2015-02-27 19:07:17 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 20:43:21 +01:00
|
|
|
qSort( lst.begin(), lst.end(), []( const QPair< QString, QString >& a,
|
|
|
|
const QPair< QString, QString >& b ) -> bool
|
|
|
|
{
|
|
|
|
return a.first > b.first;
|
|
|
|
} );
|
2015-02-27 20:31:17 +01:00
|
|
|
|
2015-02-27 19:07:17 +01:00
|
|
|
QStringList goodNews;
|
|
|
|
QProcess process;
|
|
|
|
|
2015-02-27 20:43:21 +01:00
|
|
|
foreach ( auto line, lst )
|
2015-02-27 19:07:17 +01:00
|
|
|
{
|
2015-02-27 20:43:21 +01:00
|
|
|
QString partPath = line.second;
|
2015-02-27 20:31:17 +01:00
|
|
|
cDebug() << "Will try to umount path" << partPath;
|
2015-02-27 19:07:17 +01:00
|
|
|
process.start( "umount", { "-lv", partPath } );
|
|
|
|
process.waitForFinished();
|
|
|
|
if ( process.exitCode() == 0 )
|
|
|
|
goodNews.append( QString( "Successfully unmounted %1." ).arg( partPath ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Calamares::JobResult ok = Calamares::JobResult::ok();
|
|
|
|
ok.setMessage( tr( "Cleared all temporary mounts." ) );
|
|
|
|
ok.setDetails( goodNews.join( "\n" ) );
|
|
|
|
|
|
|
|
cDebug() << "ClearTempMountsJob finished. Here's what was done:\n" << goodNews.join( "\n" );
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|