File indexing completed on 2024-04-28 05:45:54

0001 /*
0002     SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
0003     SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
0004 
0005     SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #include "jobs/resizevolumegroupjob.h"
0009 
0010 #include "core/lvmdevice.h"
0011 #include "fs/luks.h"
0012 
0013 #include "util/report.h"
0014 
0015 #include <KLocalizedString>
0016 
0017 /** Creates a new ResizeVolumeGroupJob
0018 */
0019 ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QList <const Partition*>& partlist, const Type type) :
0020     Job(),
0021     m_Device(dev),
0022     m_PartList(partlist),
0023     m_Type(type)
0024 {
0025 }
0026 
0027 bool ResizeVolumeGroupJob::run(Report& parent)
0028 {
0029     bool rval = false;
0030 
0031     Report* report = jobStarted(parent);
0032 
0033     for (const auto &p : partList()) {
0034         const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast<const FS::luks*>(&p->fileSystem())->mapperName() : p->partitionPath();
0035         if (type() == ResizeVolumeGroupJob::Type::Grow)
0036             rval = LvmDevice::insertPV(*report, device(), deviceNode);
0037         else if (type() == ResizeVolumeGroupJob::Type::Shrink)
0038             rval = LvmDevice::removePV(*report, device(), deviceNode);
0039 
0040         if (rval == false)
0041             break;
0042     }
0043 
0044     jobFinished(*report, rval);
0045 
0046     return rval;
0047 }
0048 
0049 QString ResizeVolumeGroupJob::description() const
0050 {
0051     QString partitionList = QString();
0052     for (const auto &p : partList()) {
0053         partitionList += p->deviceNode() + QStringLiteral(", ");
0054     }
0055     partitionList.chop(2);
0056     const qint32 count = partList().count();
0057 
0058     if (type() == ResizeVolumeGroupJob::Type::Grow) {
0059         return xi18ncp("@info/plain", "Adding LVM Physical Volume %2 to %3.", "Adding LVM Physical Volumes %2 to %3.", count, partitionList, device().name());
0060     }
0061     if (type() == ResizeVolumeGroupJob::Type::Shrink) {
0062         return xi18ncp("@info/plain", "Removing LVM Physical Volume %2 from %3.", "Removing LVM Physical Volumes %2 from %3.", count, partitionList, device().name());
0063     }
0064     return xi18nc("@info/plain", "Resizing Volume Group %1 to %2.", device().name(), partitionList);
0065 }