Reimplement ClearMountsJob without relying on PCM state.

main
Teo Mrnjavac 10 years ago
parent 1eff260637
commit 8b753bd65f

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -25,6 +25,7 @@
#include <util/report.h> #include <util/report.h>
#include <utils/Logger.h> #include <utils/Logger.h>
#include <QProcess>
#include <QStringList> #include <QStringList>
@ -48,33 +49,38 @@ ClearMountsJob::exec()
{ {
cDebug() << "Executing ClearMounts job for device" << m_device->deviceNode(); cDebug() << "Executing ClearMounts job for device" << m_device->deviceNode();
QStringList goodNews; QStringList goodNews;
for ( auto it = PartitionIterator::begin( m_device );
it != PartitionIterator::end( m_device ); ++it ) QProcess process;
process.setProgram( "sh" );
process.setArguments( {
"-c",
QString( "echo $(awk '{print $4}' /proc/partitions | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d' | grep %1)" )
.arg( m_device->deviceNode().split( '/' ).last() )
} );
process.start();
process.waitForFinished();
QString partitions = process.readAllStandardOutput();
QStringList partitionsList = partitions.simplified().split( ' ' );
cDebug() << "Raw:" << partitions;
cDebug() << "List:" << partitionsList.join( ", " );
foreach ( QString p, partitionsList )
{ {
cDebug() << "Now examining device" << (*it)->partitionPath(); QString partPath = QString( "/dev/%1" ).arg( p );
if ( (*it)->isMounted() )
{ process.start( "umount", { partPath } );
cDebug() << "\tIt's mounted!"; process.waitForFinished();
if ( (*it)->canUnmount() ) if ( process.exitCode() == 0 )
{ goodNews.append( QString( "Successfully unmounted %1." ).arg( partPath ) );
cDebug() << "\tTrying to umount...";
Report report( 0, QString() ); process.start( "swapoff", { partPath } );
(*it)->unmount( report ); process.waitForFinished();
goodNews.append( report.toText() ); if ( process.exitCode() == 0 )
cDebug() << "\tUmounted" << (*it)->partitionPath(); goodNews.append( QString( "Successfully disabled swap %1." ).arg( partPath ) );
}
else
{
cDebug() << "\tCannot umount. This is very bad.";
return Calamares::JobResult::error( tr( "Cannot umount partition %1" )
.arg( (*it)->deviceNode() ),
tr( "Cannot proceed with partitioning operations "
"because some partitions are still mounted." ) );
}
}
else
cDebug() << "\tIt's not mounted.";
} }
Calamares::JobResult ok = Calamares::JobResult::ok(); Calamares::JobResult ok = Calamares::JobResult::ok();
ok.setMessage( tr( "Cleared all mounts for %1" ) ok.setMessage( tr( "Cleared all mounts for %1" )
.arg( m_device->deviceNode() ) ); .arg( m_device->deviceNode() ) );

Loading…
Cancel
Save