File indexing completed on 2024-05-05 05:48:51

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2012-2016 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2016 Teo Mrnjavac <teo@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-3.0-or-later
0007 */
0008 
0009 #include "ops/checkoperation.h"
0010 
0011 #include "core/partition.h"
0012 #include "core/device.h"
0013 
0014 #include "jobs/checkfilesystemjob.h"
0015 #include "jobs/resizefilesystemjob.h"
0016 
0017 #include "util/capacity.h"
0018 
0019 #include <QString>
0020 
0021 #include <KLocalizedString>
0022 
0023 /** Creates a new CheckOperation.
0024     @param d the Device where the Partition to check is on.
0025     @param p the Partition to check
0026 */
0027 CheckOperation::CheckOperation(Device& d, Partition& p) :
0028     Operation(),
0029     m_TargetDevice(d),
0030     m_CheckedPartition(p),
0031     m_CheckJob(new CheckFileSystemJob(checkedPartition())),
0032     m_MaximizeJob(new ResizeFileSystemJob(targetDevice(), checkedPartition()))
0033 {
0034     addJob(checkJob());
0035     addJob(maximizeJob());
0036 }
0037 
0038 bool CheckOperation::targets(const Device& d) const
0039 {
0040     return d == targetDevice();
0041 }
0042 
0043 bool CheckOperation::targets(const Partition& p) const
0044 {
0045     return p == checkedPartition();
0046 }
0047 
0048 QString CheckOperation::description() const
0049 {
0050     return xi18nc("@info:status", "Check and repair partition <filename>%1</filename> (%2, %3)", checkedPartition().deviceNode(), Capacity::formatByteSize(checkedPartition().capacity()), checkedPartition().fileSystem().name());
0051 }
0052 
0053 /** Can a Partition be checked?
0054     @param p the Partition in question, may be nullptr.
0055     @return true if @p p can be checked.
0056 */
0057 bool CheckOperation::canCheck(const Partition* p)
0058 {
0059     if (p == nullptr)
0060         return false;
0061 
0062     if (p->isMounted())
0063         return p->fileSystem().supportCheckOnline() != FileSystem::cmdSupportNone;
0064 
0065     return p->fileSystem().supportCheck() != FileSystem::cmdSupportNone;
0066 }
0067