2014-08-05 14:57:00 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2015-04-09 15:16:09 +02:00
|
|
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
2017-10-27 13:55:09 +02:00
|
|
|
* Copyright 2017, Andrius Štikonas <andrius@stikonas.eu>
|
2014-08-05 14:57:00 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "jobs/ResizePartitionJob.h"
|
2014-08-05 14:57:00 +02:00
|
|
|
|
2015-07-02 13:49:21 +02:00
|
|
|
// KPMcore
|
2017-10-27 13:55:09 +02:00
|
|
|
#include <core/device.h>
|
|
|
|
#include <ops/resizeoperation.h>
|
|
|
|
#include <util/report.h>
|
2014-08-05 14:57:00 +02:00
|
|
|
|
|
|
|
//- ResizePartitionJob ---------------------------------------------------------
|
|
|
|
ResizePartitionJob::ResizePartitionJob( Device* device, Partition* partition, qint64 firstSector, qint64 lastSector )
|
|
|
|
: PartitionJob( partition )
|
|
|
|
, m_device( device )
|
2014-08-05 16:11:34 +02:00
|
|
|
, m_oldFirstSector( partition->firstSector() ) // Keep a copy of old sectors because they will be overwritten in updatePreview()
|
|
|
|
, m_oldLastSector( partition->lastSector() )
|
2014-08-05 14:57:00 +02:00
|
|
|
, m_newFirstSector( firstSector )
|
|
|
|
, m_newLastSector( lastSector )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
ResizePartitionJob::prettyName() const
|
|
|
|
{
|
2014-08-06 11:48:03 +02:00
|
|
|
// FIXME: Copy PM ResizeOperation code which generates a description of the
|
|
|
|
// operation
|
|
|
|
return tr( "Resize partition %1." ).arg( partition()->partitionPath() );
|
2014-08-05 14:57:00 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 15:16:09 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
ResizePartitionJob::prettyDescription() const
|
|
|
|
{
|
2015-04-10 13:08:26 +02:00
|
|
|
return tr( "Resize <strong>%2MB</strong> partition <strong>%1</strong> to "
|
|
|
|
"<strong>%3MB</strong>." )
|
2015-04-09 15:16:09 +02:00
|
|
|
.arg( partition()->partitionPath() )
|
2017-10-27 03:28:17 +02:00
|
|
|
.arg( ( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 )
|
2015-04-09 15:16:09 +02:00
|
|
|
.arg( ( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 );
|
|
|
|
}
|
|
|
|
|
2015-06-13 02:26:38 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
ResizePartitionJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Resizing %2MB partition %1 to "
|
|
|
|
"%3MB." )
|
|
|
|
.arg( partition()->partitionPath() )
|
2017-10-27 13:55:09 +02:00
|
|
|
.arg( ( m_oldLastSector - m_oldFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 )
|
2015-06-13 02:26:38 +02:00
|
|
|
.arg( ( m_newLastSector - m_newFirstSector + 1 ) * partition()->sectorSize() / 1024 / 1024 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-05 14:57:00 +02:00
|
|
|
Calamares::JobResult
|
|
|
|
ResizePartitionJob::exec()
|
|
|
|
{
|
2017-10-27 13:55:09 +02:00
|
|
|
Report report (nullptr);
|
|
|
|
// Restore partition sectors that were modified for preview
|
2014-08-05 18:27:24 +02:00
|
|
|
m_partition->setFirstSector( m_oldFirstSector );
|
|
|
|
m_partition->setLastSector( m_oldLastSector );
|
2017-10-27 13:55:09 +02:00
|
|
|
ResizeOperation op(*m_device, *m_partition, m_newFirstSector, m_newLastSector);
|
|
|
|
op.setStatus(Operation::StatusRunning);
|
|
|
|
connect(&op, &Operation::progress, [&](int percent) { emit progress(percent / 100.0); } );
|
2014-08-05 18:27:24 +02:00
|
|
|
|
2017-10-27 13:55:09 +02:00
|
|
|
QString errorMessage = tr( "The installer failed to resize partition %1 on disk '%2'." )
|
|
|
|
.arg( m_partition->partitionPath() )
|
|
|
|
.arg( m_device->name() );
|
|
|
|
if (op.execute(report))
|
|
|
|
return Calamares::JobResult::ok();
|
2014-08-05 14:57:00 +02:00
|
|
|
|
2017-10-27 13:55:09 +02:00
|
|
|
return Calamares::JobResult::error(errorMessage, report.toText());
|
2014-08-05 14:57:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResizePartitionJob::updatePreview()
|
|
|
|
{
|
|
|
|
m_device->partitionTable()->removeUnallocated();
|
|
|
|
m_partition->parent()->remove( m_partition );
|
|
|
|
m_partition->setFirstSector( m_newFirstSector );
|
|
|
|
m_partition->setLastSector( m_newLastSector );
|
|
|
|
m_partition->parent()->insert( m_partition );
|
|
|
|
m_device->partitionTable()->updateUnallocated( *m_device );
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:13:07 +01:00
|
|
|
|
|
|
|
Device*
|
|
|
|
ResizePartitionJob::device() const
|
|
|
|
{
|
|
|
|
return m_device;
|
|
|
|
}
|