1 /*
2     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
3     SPDX-FileCopyrightText: 2012-2018 Andrius Štikonas <andrius@stikonas.eu>
4     SPDX-FileCopyrightText: 2016 Teo Mrnjavac <teo@kde.org>
5 
6     SPDX-License-Identifier: GPL-3.0-or-later
7 */
8 
9 #include "ops/backupoperation.h"
10 
11 #include "core/partition.h"
12 #include "core/device.h"
13 
14 #include "jobs/backupfilesystemjob.h"
15 
16 #include "util/capacity.h"
17 
18 #include <QString>
19 
20 #include <KLocalizedString>
21 
22 /** Creates a new BackupOperation.
23     @param d the Device where the FileSystem to back up is on
24     @param p the Partition where the FileSystem to back up is in
25     @param filename the name of the file to back up to
26 */
BackupOperation(Device & d,Partition & p,const QString & filename)27 BackupOperation::BackupOperation(Device& d, Partition& p, const QString& filename) :
28     Operation(),
29     m_TargetDevice(d),
30     m_BackupPartition(p),
31     m_FileName(filename),
32     m_BackupJob(new BackupFileSystemJob(targetDevice(), backupPartition(), fileName()))
33 {
34     addJob(backupJob());
35 }
36 
description() const37 QString BackupOperation::description() const
38 {
39     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());
40 }
41 
42 /** Can the given Partition be backed up?
43     @param p The Partition in question, may be nullptr.
44     @return true if @p p can be backed up.
45 */
canBackup(const Partition * p)46 bool BackupOperation::canBackup(const Partition* p)
47 {
48     if (p == nullptr)
49         return false;
50 
51     if (p->isMounted())
52         return false;
53 
54     if (p->state() == Partition::State::New || p->state() == Partition::State::Copy || p->state() == Partition::State::Restore)
55         return false;
56 
57     return p->fileSystem().supportBackup() != FileSystem::cmdSupportNone;
58 }
59 
60