Commit 6c14ddb0 authored by Tomaz  Canabrava's avatar Tomaz Canabrava Committed by Andrius Štikonas
Browse files

Add new job to change permission of the newly created partition

parent 68c8fecf
......@@ -368,6 +368,25 @@ void Partition::setPartitionPath(const QString& s)
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)
{
m_FileSystem = fs;
......
......@@ -259,6 +259,14 @@ public:
}
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:
void setNumber(qint32 n) {
m_Number = n;
......@@ -275,6 +283,7 @@ private:
QString m_Label;
QString m_Type;
QString m_UUID;
QString m_permission;
quint64 m_Attributes = 0;
QString m_PartitionPath;
QString m_MountPoint;
......
......@@ -31,6 +31,7 @@ set(JOBS_SRC
jobs/setpartflagsjob.cpp
jobs/copyfilesystemjob.cpp
jobs/movefilesystemjob.cpp
jobs/changepermissionsjob.cpp
)
set(JOBS_LIB_HDRS
......
/*
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);
}
/*
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/createfilesystemjob.h"
#include "jobs/checkfilesystemjob.h"
#include "jobs/changepermissionsjob.h"
#include "fs/filesystem.h"
#include "fs/filesystemfactory.h"
......@@ -42,6 +43,10 @@ CreateFileSystemOperation::CreateFileSystemOperation(Device& d, Partition& p, Fi
addJob(deleteJob());
addJob(createJob());
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()
......
......@@ -21,6 +21,7 @@
#include "jobs/setfilesystemlabeljob.h"
#include "jobs/setpartflagsjob.h"
#include "jobs/checkfilesystemjob.h"
#include "jobs/changepermissionsjob.h"
#include "fs/filesystem.h"
#include "fs/filesystemfactory.h"
......@@ -106,6 +107,10 @@ NewOperation::NewOperation(Device& d, Partition* p) :
d_ptr->m_CheckFileSystemJob = new CheckFileSystemJob(newPartition());
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()));
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment