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

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

sync with github

File size: 3.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/CreatePartitionTableJob.h"
22
23#include "utils/Logger.h"
24
25// KPMcore
26#include <core/device.h>
27#include <core/partition.h>
28#include <core/partitiontable.h>
29#include <fs/filesystem.h>
30#include <ops/createpartitiontableoperation.h>
31#include <util/report.h>
32
33// Qt
34#include <QProcess>
35
36CreatePartitionTableJob::CreatePartitionTableJob( Device* device, PartitionTable::TableType type )
37    : m_device( device )
38    , m_type( type )
39{
40}
41
42QString
43CreatePartitionTableJob::prettyName() const
44{
45    return tr( "Create new %1 partition table on %2." )
46            .arg( PartitionTable::tableTypeToName( m_type ) )
47            .arg( m_device->deviceNode() );
48}
49
50QString CreatePartitionTableJob::prettyDescription() const
51{
52    return tr( "Create new <strong>%1</strong> partition table on <strong>%2</strong> (%3)." )
53            .arg( PartitionTable::tableTypeToName( m_type ).toUpper() )
54            .arg( m_device->deviceNode() )
55            .arg( m_device->name() );
56}
57
58
59QString
60CreatePartitionTableJob::prettyStatusMessage() const
61{
62    return tr( "Creating new %1 partition table on %2." )
63            .arg( PartitionTable::tableTypeToName( m_type ).toUpper() )
64            .arg( m_device->deviceNode() );
65}
66
67
68Calamares::JobResult
69CreatePartitionTableJob::exec()
70{
71    Report report( nullptr );
72    QString message = tr( "The installer failed to create a partition table on %1." ).arg( m_device->name() );
73
74    PartitionTable* table = m_device->partitionTable();
75    cDebug() << "Creating new partition table of type" << table->typeName()
76             << ", uncommitted yet:\n" << table;
77
78    QProcess lsblk;
79    lsblk.setProgram( "lsblk" );
80    lsblk.setProcessChannelMode( QProcess::MergedChannels );
81    lsblk.start();
82    lsblk.waitForFinished();
83    cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();
84
85    QProcess mount;
86    mount.setProgram( "mount" );
87    mount.setProcessChannelMode( QProcess::MergedChannels );
88    mount.start();
89    mount.waitForFinished();
90    cDebug() << "mount:\n" << mount.readAllStandardOutput();
91
92    CreatePartitionTableOperation op(*m_device, table);
93    op.setStatus(Operation::StatusRunning);
94
95    if (op.execute(report))
96        return Calamares::JobResult::ok();
97
98    return Calamares::JobResult::error(message, report.toText());
99}
100
101void
102CreatePartitionTableJob::updatePreview()
103{
104    // Device takes ownership of its table, but does not destroy the current
105    // one when setPartitionTable() is called, so do it ourself
106    delete m_device->partitionTable();
107    m_device->setPartitionTable( createTable() );
108    m_device->partitionTable()->updateUnallocated( *m_device );
109}
110
111PartitionTable*
112CreatePartitionTableJob::createTable()
113{
114    cDebug() << "CreatePartitionTableJob::createTable trying to make table for device"
115             << m_device->deviceNode();
116    return new PartitionTable( m_type,
117                               PartitionTable::defaultFirstUsable( *m_device, m_type ),
118                               PartitionTable::defaultLastUsable( *m_device, m_type )
119                             );
120}
Note: See TracBrowser for help on using the repository browser.