2020-09-30 23:28:47 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008-2011 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include "ops/createfilesystemoperation.h"
|
|
|
|
|
|
|
|
#include "core/partition.h"
|
|
|
|
#include "core/device.h"
|
|
|
|
|
|
|
|
#include "jobs/deletefilesystemjob.h"
|
|
|
|
#include "jobs/createfilesystemjob.h"
|
|
|
|
#include "jobs/checkfilesystemjob.h"
|
2021-12-09 15:54:41 +00:00
|
|
|
#include "jobs/changepermissionsjob.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include "fs/filesystem.h"
|
|
|
|
#include "fs/filesystemfactory.h"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
/** Creates a new CreateFileSystemOperation.
|
2015-07-13 15:16:36 +01:00
|
|
|
@param d the Device to create the new FileSystem on
|
|
|
|
@param p the Partition to create the new FileSystem in
|
|
|
|
@param newType the type of the new FileSystem
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
CreateFileSystemOperation::CreateFileSystemOperation(Device& d, Partition& p, FileSystem::Type newType) :
|
2015-07-13 15:16:36 +01:00
|
|
|
Operation(),
|
|
|
|
m_TargetDevice(d),
|
|
|
|
m_Partition(p),
|
|
|
|
m_NewFileSystem(FileSystemFactory::cloneWithNewType(newType, partition().fileSystem())),
|
|
|
|
m_OldFileSystem(&p.fileSystem()),
|
|
|
|
m_DeleteJob(new DeleteFileSystemJob(targetDevice(), partition())),
|
|
|
|
m_CreateJob(new CreateFileSystemJob(targetDevice(), partition())),
|
|
|
|
m_CheckJob(new CheckFileSystemJob(partition()))
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
// We never know anything about the number of used sectors on a new file system.
|
|
|
|
newFileSystem()->setSectorsUsed(-1);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
addJob(deleteJob());
|
|
|
|
addJob(createJob());
|
|
|
|
addJob(checkJob());
|
2021-12-09 15:54:41 +00:00
|
|
|
|
|
|
|
// if the user never configured a new permission, nothing will run, if he did,
|
|
|
|
// then we change the permissions on the newly created partition.
|
|
|
|
addJob(new ChangePermissionJob(p));
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateFileSystemOperation::~CreateFileSystemOperation()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
if (&partition().fileSystem() == newFileSystem())
|
|
|
|
delete oldFileSystem();
|
|
|
|
else
|
|
|
|
delete newFileSystem();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CreateFileSystemOperation::targets(const Device& d) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return d == targetDevice();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CreateFileSystemOperation::targets(const Partition& p) const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return p == partition();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateFileSystemOperation::preview()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
partition().setFileSystem(newFileSystem());
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateFileSystemOperation::undo()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
partition().setFileSystem(oldFileSystem());
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CreateFileSystemOperation::execute(Report& parent)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
preview();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return Operation::execute(parent);
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CreateFileSystemOperation::description() const
|
|
|
|
{
|
2016-07-17 23:41:00 +01:00
|
|
|
return xi18nc("@info:status", "Create filesystem %1 on partition <filename>%2</filename>", newFileSystem()->name(), partition().deviceNode());
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|