2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2016-03-04 19:10:16 +01:00
|
|
|
*
|
|
|
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Based on the SetPartFlagsJob class from KDE Partition Manager,
|
|
|
|
* Copyright 2008, 2010, Volker Lanz <vl@fidra.de>
|
|
|
|
*
|
|
|
|
* 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 "SetPartitionFlagsJob.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
2017-12-14 22:00:46 +01:00
|
|
|
#include "utils/Units.h"
|
2016-03-04 19:10:16 +01:00
|
|
|
|
2017-12-06 15:47:54 +01:00
|
|
|
// KPMcore
|
|
|
|
#include <core/device.h>
|
|
|
|
#include <core/partition.h>
|
|
|
|
#include <fs/filesystem.h>
|
|
|
|
#include <ops/setpartflagsoperation.h>
|
|
|
|
#include <util/report.h>
|
2016-03-04 19:10:16 +01:00
|
|
|
|
2017-12-14 22:00:46 +01:00
|
|
|
using CalamaresUtils::BytesToMiB;
|
|
|
|
|
2016-03-04 19:10:16 +01:00
|
|
|
SetPartFlagsJob::SetPartFlagsJob( Device* device,
|
2017-12-14 21:55:23 +01:00
|
|
|
Partition* partition,
|
|
|
|
PartitionTable::Flags flags )
|
2016-03-04 19:10:16 +01:00
|
|
|
: PartitionJob( partition )
|
|
|
|
, m_device( device )
|
|
|
|
, m_flags( flags )
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
SetPartFlagsJob::prettyName() const
|
|
|
|
{
|
2016-10-28 09:23:33 +02:00
|
|
|
if ( !partition()->partitionPath().isEmpty() )
|
|
|
|
return tr( "Set flags on partition %1." ).arg( partition()->partitionPath() );
|
|
|
|
|
|
|
|
if ( !partition()->fileSystem().name().isEmpty() )
|
|
|
|
return tr( "Set flags on %1MB %2 partition." )
|
2017-12-14 22:00:46 +01:00
|
|
|
.arg( BytesToMiB( partition()->capacity() ) )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->fileSystem().name() );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
return tr( "Set flags on new partition." );
|
2016-03-04 19:10:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
SetPartFlagsJob::prettyDescription() const
|
|
|
|
{
|
|
|
|
QStringList flagsList = PartitionTable::flagNames( m_flags );
|
|
|
|
if ( flagsList.count() == 0 )
|
2016-10-28 09:23:33 +02:00
|
|
|
{
|
|
|
|
if ( !partition()->partitionPath().isEmpty() )
|
|
|
|
return tr( "Clear flags on partition <strong>%1</strong>." )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->partitionPath() );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
if ( !partition()->fileSystem().name().isEmpty() )
|
|
|
|
return tr( "Clear flags on %1MB <strong>%2</strong> partition." )
|
2017-12-14 22:00:46 +01:00
|
|
|
.arg( BytesToMiB( partition()->capacity() ) )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->fileSystem().name() );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
return tr( "Clear flags on new partition." );
|
|
|
|
}
|
2016-03-04 19:10:16 +01:00
|
|
|
|
2016-10-28 09:23:33 +02:00
|
|
|
if ( !partition()->partitionPath().isEmpty() )
|
|
|
|
return tr( "Flag partition <strong>%1</strong> as "
|
|
|
|
"<strong>%2</strong>." )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->partitionPath() )
|
|
|
|
.arg( flagsList.join( ", " ) );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
if ( !partition()->fileSystem().name().isEmpty() )
|
|
|
|
return tr( "Flag %1MB <strong>%2</strong> partition as "
|
|
|
|
"<strong>%3</strong>." )
|
2017-12-14 22:00:46 +01:00
|
|
|
.arg( BytesToMiB( partition()->capacity() ) )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->fileSystem().name() )
|
|
|
|
.arg( flagsList.join( ", " ) );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
return tr( "Flag new partition as <strong>%1</strong>." )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( flagsList.join( ", " ) );
|
2016-03-04 19:10:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
SetPartFlagsJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
QStringList flagsList = PartitionTable::flagNames( m_flags );
|
|
|
|
if ( flagsList.count() == 0 )
|
2016-10-28 09:23:33 +02:00
|
|
|
{
|
|
|
|
if ( !partition()->partitionPath().isEmpty() )
|
|
|
|
return tr( "Clearing flags on partition <strong>%1</strong>." )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->partitionPath() );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
if ( !partition()->fileSystem().name().isEmpty() )
|
|
|
|
return tr( "Clearing flags on %1MB <strong>%2</strong> partition." )
|
2017-12-14 22:00:46 +01:00
|
|
|
.arg( BytesToMiB( partition()->capacity() ) )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->fileSystem().name() );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
return tr( "Clearing flags on new partition." );
|
|
|
|
}
|
2016-03-04 19:10:16 +01:00
|
|
|
|
2016-10-28 09:23:33 +02:00
|
|
|
if ( !partition()->partitionPath().isEmpty() )
|
|
|
|
return tr( "Setting flags <strong>%2</strong> on partition "
|
|
|
|
"<strong>%1</strong>." )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->partitionPath() )
|
|
|
|
.arg( flagsList.join( ", " ) );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
if ( !partition()->fileSystem().name().isEmpty() )
|
|
|
|
return tr( "Setting flags <strong>%3</strong> on "
|
|
|
|
"%1MB <strong>%2</strong> partition." )
|
2017-12-14 22:00:46 +01:00
|
|
|
.arg( BytesToMiB( partition()->capacity() ) )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( partition()->fileSystem().name() )
|
|
|
|
.arg( flagsList.join( ", " ) );
|
2016-10-28 09:23:33 +02:00
|
|
|
|
|
|
|
return tr( "Setting flags <strong>%1</strong> on new partition." )
|
2017-12-14 21:55:23 +01:00
|
|
|
.arg( flagsList.join( ", " ) );
|
2016-03-04 19:10:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Calamares::JobResult
|
|
|
|
SetPartFlagsJob::exec()
|
|
|
|
{
|
2018-10-05 13:45:05 +02:00
|
|
|
cDebug() << "Setting flags on" << m_device->deviceNode()
|
|
|
|
<< "partition" << partition()->deviceNode()
|
|
|
|
<< "to" << m_flags;
|
|
|
|
|
2017-12-14 21:55:23 +01:00
|
|
|
Report report ( nullptr );
|
|
|
|
SetPartFlagsOperation op( *m_device, *partition(), m_flags );
|
|
|
|
op.setStatus( Operation::StatusRunning );
|
2017-12-25 21:48:55 +01:00
|
|
|
connect( &op, &Operation::progress, this, &SetPartFlagsJob::iprogress );
|
2016-03-04 19:10:16 +01:00
|
|
|
|
|
|
|
QString errorMessage = tr( "The installer failed to set flags on partition %1." )
|
|
|
|
.arg( m_partition->partitionPath() );
|
2017-12-14 21:55:23 +01:00
|
|
|
if ( op.execute( report ) )
|
2017-12-06 15:47:54 +01:00
|
|
|
return Calamares::JobResult::ok();
|
2016-03-04 19:10:16 +01:00
|
|
|
|
2017-12-14 21:55:23 +01:00
|
|
|
return Calamares::JobResult::error( errorMessage, report.toText() );
|
2016-03-04 19:10:16 +01:00
|
|
|
}
|