Add new job to change permission of the newly created partition
This commit is contained in:
parent
68c8fecffd
commit
6c14ddb043
|
@ -368,6 +368,25 @@ void Partition::setPartitionPath(const QString& s)
|
||||||
setNumber(-1);
|
setNumber(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Partition::execChangePermission(Report& report)
|
||||||
|
{
|
||||||
|
if (m_permission.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalCommand chmodCmd(report,
|
||||||
|
QStringLiteral("chmod"),
|
||||||
|
{
|
||||||
|
m_permission,
|
||||||
|
deviceNode()
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( chmodCmd.run() && chmodCmd.exitCode() == 0 )
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Partition::setFileSystem(FileSystem* fs)
|
void Partition::setFileSystem(FileSystem* fs)
|
||||||
{
|
{
|
||||||
m_FileSystem = fs;
|
m_FileSystem = fs;
|
||||||
|
|
|
@ -259,6 +259,14 @@ public:
|
||||||
}
|
}
|
||||||
void deleteFileSystem();
|
void deleteFileSystem();
|
||||||
|
|
||||||
|
void setPermissions(const QString& permission) {
|
||||||
|
m_permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets the disk to have write and read permissions of 777.
|
||||||
|
// userful for pendrives and such.
|
||||||
|
bool execChangePermission(Report& report);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setNumber(qint32 n) {
|
void setNumber(qint32 n) {
|
||||||
m_Number = n;
|
m_Number = n;
|
||||||
|
@ -275,6 +283,7 @@ private:
|
||||||
QString m_Label;
|
QString m_Label;
|
||||||
QString m_Type;
|
QString m_Type;
|
||||||
QString m_UUID;
|
QString m_UUID;
|
||||||
|
QString m_permission;
|
||||||
quint64 m_Attributes = 0;
|
quint64 m_Attributes = 0;
|
||||||
QString m_PartitionPath;
|
QString m_PartitionPath;
|
||||||
QString m_MountPoint;
|
QString m_MountPoint;
|
||||||
|
|
|
@ -31,6 +31,7 @@ set(JOBS_SRC
|
||||||
jobs/setpartflagsjob.cpp
|
jobs/setpartflagsjob.cpp
|
||||||
jobs/copyfilesystemjob.cpp
|
jobs/copyfilesystemjob.cpp
|
||||||
jobs/movefilesystemjob.cpp
|
jobs/movefilesystemjob.cpp
|
||||||
|
jobs/changepermissionsjob.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(JOBS_LIB_HDRS
|
set(JOBS_LIB_HDRS
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: Tomaz Canabrava <tcanabrava@kde.org>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "jobs/changepermissionsjob.h"
|
||||||
|
|
||||||
|
#include "core/lvmdevice.h"
|
||||||
|
#include "core/partition.h"
|
||||||
|
|
||||||
|
#include "util/report.h"
|
||||||
|
|
||||||
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
/** Creates a new CreateVolumeGroupJob
|
||||||
|
* @param permission the new permission for the partition, in chmod style.
|
||||||
|
* @param partition the partition to change the permission.
|
||||||
|
*/
|
||||||
|
ChangePermissionJob::ChangePermissionJob(Partition& partition) :
|
||||||
|
Job(),
|
||||||
|
m_Partition(partition)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChangePermissionJob::run(Report& parent)
|
||||||
|
{
|
||||||
|
bool rval = false;
|
||||||
|
|
||||||
|
Report* report = jobStarted(parent);
|
||||||
|
|
||||||
|
rval = m_Partition.execChangePermission(*report);
|
||||||
|
|
||||||
|
jobFinished(*report, rval);
|
||||||
|
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ChangePermissionJob::description() const
|
||||||
|
{
|
||||||
|
return xi18nc("@info/plain", "Change the permissions of: <filename>%1</filename> to %2", m_Partition.deviceNode(), m_permissions);
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: 2021 Tomaz Canabrava <tcanabrava@kde.org>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KPMCORE_CHANGEPERMISSIONJOB_H
|
||||||
|
#define KPMCORE_CHANGEPERMISSIONJOB_H
|
||||||
|
|
||||||
|
#include "jobs/job.h"
|
||||||
|
|
||||||
|
class Partition;
|
||||||
|
class Report;
|
||||||
|
|
||||||
|
class QString;
|
||||||
|
|
||||||
|
/** Check a FileSystem.
|
||||||
|
@author Volker Lanz <vl@fidra.de>
|
||||||
|
*/
|
||||||
|
class ChangePermissionJob : public Job
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/* Permission should be set in the partition. */
|
||||||
|
explicit ChangePermissionJob(Partition& p);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool run(Report& parent) override;
|
||||||
|
QString description() const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Partition& partition() {
|
||||||
|
return m_Partition;
|
||||||
|
}
|
||||||
|
const Partition& partition() const {
|
||||||
|
return m_Partition;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Partition& m_Partition;
|
||||||
|
QString m_permissions;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -13,6 +13,7 @@
|
||||||
#include "jobs/deletefilesystemjob.h"
|
#include "jobs/deletefilesystemjob.h"
|
||||||
#include "jobs/createfilesystemjob.h"
|
#include "jobs/createfilesystemjob.h"
|
||||||
#include "jobs/checkfilesystemjob.h"
|
#include "jobs/checkfilesystemjob.h"
|
||||||
|
#include "jobs/changepermissionsjob.h"
|
||||||
|
|
||||||
#include "fs/filesystem.h"
|
#include "fs/filesystem.h"
|
||||||
#include "fs/filesystemfactory.h"
|
#include "fs/filesystemfactory.h"
|
||||||
|
@ -42,6 +43,10 @@ CreateFileSystemOperation::CreateFileSystemOperation(Device& d, Partition& p, Fi
|
||||||
addJob(deleteJob());
|
addJob(deleteJob());
|
||||||
addJob(createJob());
|
addJob(createJob());
|
||||||
addJob(checkJob());
|
addJob(checkJob());
|
||||||
|
|
||||||
|
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateFileSystemOperation::~CreateFileSystemOperation()
|
CreateFileSystemOperation::~CreateFileSystemOperation()
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "jobs/setfilesystemlabeljob.h"
|
#include "jobs/setfilesystemlabeljob.h"
|
||||||
#include "jobs/setpartflagsjob.h"
|
#include "jobs/setpartflagsjob.h"
|
||||||
#include "jobs/checkfilesystemjob.h"
|
#include "jobs/checkfilesystemjob.h"
|
||||||
|
#include "jobs/changepermissionsjob.h"
|
||||||
|
|
||||||
#include "fs/filesystem.h"
|
#include "fs/filesystem.h"
|
||||||
#include "fs/filesystemfactory.h"
|
#include "fs/filesystemfactory.h"
|
||||||
|
@ -106,6 +107,10 @@ NewOperation::NewOperation(Device& d, Partition* p) :
|
||||||
|
|
||||||
d_ptr->m_CheckFileSystemJob = new CheckFileSystemJob(newPartition());
|
d_ptr->m_CheckFileSystemJob = new CheckFileSystemJob(newPartition());
|
||||||
addJob(checkJob());
|
addJob(checkJob());
|
||||||
|
|
||||||
|
// 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(newPartition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue