File indexing completed on 2024-05-05 05:48:51
0001 /* 0002 SPDX-FileCopyrightText: 2008-2011 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu> 0004 0005 SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 #include "ops/createfilesystemoperation.h" 0009 0010 #include "core/partition.h" 0011 #include "core/device.h" 0012 0013 #include "jobs/deletefilesystemjob.h" 0014 #include "jobs/createfilesystemjob.h" 0015 #include "jobs/checkfilesystemjob.h" 0016 #include "jobs/changepermissionsjob.h" 0017 0018 #include "fs/filesystem.h" 0019 #include "fs/filesystemfactory.h" 0020 0021 #include <QString> 0022 0023 #include <KLocalizedString> 0024 0025 /** Creates a new CreateFileSystemOperation. 0026 @param d the Device to create the new FileSystem on 0027 @param p the Partition to create the new FileSystem in 0028 @param newType the type of the new FileSystem 0029 */ 0030 CreateFileSystemOperation::CreateFileSystemOperation(Device& d, Partition& p, FileSystem::Type newType) : 0031 Operation(), 0032 m_TargetDevice(d), 0033 m_Partition(p), 0034 m_NewFileSystem(FileSystemFactory::cloneWithNewType(newType, partition().fileSystem())), 0035 m_OldFileSystem(&p.fileSystem()), 0036 m_DeleteJob(new DeleteFileSystemJob(targetDevice(), partition())), 0037 m_CreateJob(new CreateFileSystemJob(targetDevice(), partition())), 0038 m_CheckJob(new CheckFileSystemJob(partition())) 0039 { 0040 // We never know anything about the number of used sectors on a new file system. 0041 newFileSystem()->setSectorsUsed(-1); 0042 0043 addJob(deleteJob()); 0044 addJob(createJob()); 0045 addJob(checkJob()); 0046 0047 // if the user never configured a new permission, nothing will run, if he did, 0048 // then we change the permissions on the newly created partition. 0049 addJob(new ChangePermissionJob(p)); 0050 } 0051 0052 CreateFileSystemOperation::~CreateFileSystemOperation() 0053 { 0054 if (&partition().fileSystem() == newFileSystem()) 0055 delete oldFileSystem(); 0056 else 0057 delete newFileSystem(); 0058 } 0059 0060 bool CreateFileSystemOperation::targets(const Device& d) const 0061 { 0062 return d == targetDevice(); 0063 } 0064 0065 bool CreateFileSystemOperation::targets(const Partition& p) const 0066 { 0067 return p == partition(); 0068 } 0069 0070 void CreateFileSystemOperation::preview() 0071 { 0072 partition().setFileSystem(newFileSystem()); 0073 } 0074 0075 void CreateFileSystemOperation::undo() 0076 { 0077 partition().setFileSystem(oldFileSystem()); 0078 } 0079 0080 bool CreateFileSystemOperation::execute(Report& parent) 0081 { 0082 preview(); 0083 0084 return Operation::execute(parent); 0085 } 0086 0087 QString CreateFileSystemOperation::description() const 0088 { 0089 return xi18nc("@info:status", "Create filesystem %1 on partition <filename>%2</filename>", newFileSystem()->name(), partition().deviceNode()); 0090 }