source: calamares/trunk/fuentes/src/modules/partition/jobs/DeletePartitionJob.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 2.9 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Aurélien Gâteau <agateau@kde.org>
4 *   Copyright 2015, Teo Mrnjavac <teo@kde.org>
5 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
6 *
7 *   Calamares is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   Calamares is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "jobs/DeletePartitionJob.h"
22
23// KPMcore
24#include <core/device.h>
25#include <core/partition.h>
26#include <core/partitiontable.h>
27#include <fs/filesystem.h>
28#include <ops/deleteoperation.h>
29#include <util/report.h>
30
31DeletePartitionJob::DeletePartitionJob( Device* device, Partition* partition )
32    : PartitionJob( partition )
33    , m_device( device )
34{
35}
36
37QString
38DeletePartitionJob::prettyName() const
39{
40    return tr( "Delete partition %1." )
41            .arg( m_partition->partitionPath() );
42}
43
44
45QString
46DeletePartitionJob::prettyDescription() const
47{
48    return tr( "Delete partition <strong>%1</strong>." )
49            .arg( m_partition->partitionPath() );
50}
51
52
53QString
54DeletePartitionJob::prettyStatusMessage() const
55{
56    return tr( "Deleting partition %1." )
57            .arg( m_partition->partitionPath() );
58}
59
60
61Calamares::JobResult
62DeletePartitionJob::exec()
63{
64    Report report( nullptr );
65    DeleteOperation op(*m_device, m_partition);
66    op.setStatus(Operation::StatusRunning);
67
68    QString message = tr( "The installer failed to delete partition %1." ).arg( m_partition->devicePath() );
69    if (op.execute(report))
70        return Calamares::JobResult::ok();
71
72    return Calamares::JobResult::error(message, report.toText());
73}
74
75void
76DeletePartitionJob::updatePreview()
77{
78    m_partition->parent()->remove( m_partition );
79    m_device->partitionTable()->updateUnallocated( *m_device );
80
81    // Copied from PM DeleteOperation::checkAdjustLogicalNumbers():
82    //
83    // If the deleted partition is a logical one, we need to adjust the numbers
84    // of the other logical partitions in the extended one, if there are any,
85    // because the OS will do that, too: Logicals must be numbered without gaps,
86    // i.e., a numbering like sda5, sda6, sda8 (after sda7 is deleted) will
87    // become sda5, sda6, sda7
88    Partition* parentPartition = dynamic_cast< Partition* >( m_partition->parent() );
89    if ( parentPartition && parentPartition->roles().has( PartitionRole::Extended ) )
90        parentPartition->adjustLogicalNumbers( m_partition->number(), -1 );
91}
Note: See TracBrowser for help on using the repository browser.