2014-11-28 15:50:27 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, 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 "ClearMountsJob.h"
|
|
|
|
|
|
|
|
#include <core/device.h>
|
|
|
|
#include <core/partition.h>
|
|
|
|
#include <core/PartitionInfo.h>
|
|
|
|
#include <core/PartitionIterator.h>
|
|
|
|
#include <util/report.h>
|
2015-02-13 11:56:10 +01:00
|
|
|
#include <utils/Logger.h>
|
2014-11-28 15:50:27 +01:00
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
|
|
ClearMountsJob::ClearMountsJob( Device* device )
|
|
|
|
: Calamares::Job()
|
|
|
|
, m_device( device )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ClearMountsJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Clear mounts for partitioning operations on %1" )
|
|
|
|
.arg( m_device->deviceNode() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Calamares::JobResult
|
|
|
|
ClearMountsJob::exec()
|
|
|
|
{
|
2015-02-13 11:56:10 +01:00
|
|
|
cDebug() << "Executing ClearMounts job for device" << m_device->deviceNode();
|
2014-11-28 15:50:27 +01:00
|
|
|
QStringList goodNews;
|
|
|
|
for ( auto it = PartitionIterator::begin( m_device );
|
|
|
|
it != PartitionIterator::end( m_device ); ++it )
|
|
|
|
{
|
2015-02-13 11:56:10 +01:00
|
|
|
cDebug() << "Now examining device" << (*it)->partitionPath();
|
2014-11-28 15:50:27 +01:00
|
|
|
if ( (*it)->isMounted() )
|
|
|
|
{
|
2015-02-13 11:56:10 +01:00
|
|
|
cDebug() << "\tIt's mounted!";
|
2014-11-28 15:50:27 +01:00
|
|
|
if ( (*it)->canUnmount() )
|
|
|
|
{
|
2015-02-13 11:56:10 +01:00
|
|
|
cDebug() << "\tTrying to umount...";
|
2014-11-28 15:50:27 +01:00
|
|
|
Report report( 0, QString() );
|
|
|
|
(*it)->unmount( report );
|
|
|
|
goodNews.append( report.toText() );
|
2015-02-13 11:56:10 +01:00
|
|
|
cDebug() << "\tUmounted" << (*it)->partitionPath();
|
2014-11-28 15:50:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-13 11:56:10 +01:00
|
|
|
cDebug() << "\tCannot umount. This is very bad.";
|
2014-11-28 15:50:27 +01:00
|
|
|
return Calamares::JobResult::error( tr( "Cannot umount partition %1" )
|
|
|
|
.arg( (*it)->deviceNode() ),
|
|
|
|
tr( "Cannot proceed with partitioning operations "
|
|
|
|
"because some partitions are still mounted." ) );
|
|
|
|
}
|
|
|
|
}
|
2015-02-13 11:56:10 +01:00
|
|
|
else
|
|
|
|
cDebug() << "\tIt's not mounted.";
|
2014-11-28 15:50:27 +01:00
|
|
|
}
|
|
|
|
Calamares::JobResult ok = Calamares::JobResult::ok();
|
|
|
|
ok.setMessage( tr( "Cleared all mounts for %1" )
|
|
|
|
.arg( m_device->deviceNode() ) );
|
|
|
|
ok.setDetails( goodNews.join( "\n" ) );
|
2015-02-13 11:56:10 +01:00
|
|
|
|
|
|
|
cDebug() << "Finished ClearMounts job.";
|
2014-11-28 15:50:27 +01:00
|
|
|
return ok;
|
|
|
|
}
|