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

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2012-2018 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/backupoperation.h"
0010 
0011 #include "core/partition.h"
0012 #include "core/device.h"
0013 
0014 #include "jobs/backupfilesystemjob.h"
0015 
0016 #include "util/capacity.h"
0017 
0018 #include <QString>
0019 
0020 #include <KLocalizedString>
0021 
0022 /** Creates a new BackupOperation.
0023     @param d the Device where the FileSystem to back up is on
0024     @param p the Partition where the FileSystem to back up is in
0025     @param filename the name of the file to back up to
0026 */
0027 BackupOperation::BackupOperation(Device& d, Partition& p, const QString& filename) :
0028     Operation(),
0029     m_TargetDevice(d),
0030     m_BackupPartition(p),
0031     m_FileName(filename),
0032     m_BackupJob(new BackupFileSystemJob(targetDevice(), backupPartition(), fileName()))
0033 {
0034     addJob(backupJob());
0035 }
0036 
0037 QString BackupOperation::description() const
0038 {
0039     return xi18nc("@info:status", "Backup partition <filename>%1</filename> (%2, %3) to <filename>%4</filename>", backupPartition().deviceNode(), Capacity::formatByteSize(backupPartition().capacity()), backupPartition().fileSystem().name(), fileName());
0040 }
0041 
0042 /** Can the given Partition be backed up?
0043     @param p The Partition in question, may be nullptr.
0044     @return true if @p p can be backed up.
0045 */
0046 bool BackupOperation::canBackup(const Partition* p)
0047 {
0048     if (p == nullptr)
0049         return false;
0050 
0051     if (p->isMounted())
0052         return false;
0053 
0054     if (p->state() == Partition::State::New || p->state() == Partition::State::Copy || p->state() == Partition::State::Restore)
0055         return false;
0056 
0057     return p->fileSystem().supportBackup() != FileSystem::cmdSupportNone;
0058 }
0059