Move the changePosixPermission to the Filesystem
And implement it on ext2, 3, 4. I don't know all the filesystems that can have posix permissions, those three will do. if we need more in the future we implement them, it's two lines of code.
This commit is contained in:
parent
6c14ddb043
commit
9093b27bd8
|
@ -368,25 +368,6 @@ 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,14 +259,6 @@ 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;
|
||||
|
|
|
@ -91,6 +91,9 @@ public:
|
|||
SupportTool supportToolName() const override;
|
||||
bool supportToolFound() const override;
|
||||
|
||||
QString posixPermissions() const override { return implPosixPermissions(); };
|
||||
void setPosixPermissions(const QString& permissions) override { implSetPosixPermissions(permissions); };
|
||||
|
||||
public:
|
||||
static CommandSupportType m_GetUsed;
|
||||
static CommandSupportType m_GetLabel;
|
||||
|
|
|
@ -42,6 +42,9 @@ public:
|
|||
CommandSupportType supportGrowOnline() const override {
|
||||
return m_Grow;
|
||||
}
|
||||
|
||||
QString posixPermissions() const override { return implPosixPermissions(); };
|
||||
void setPosixPermissions(const QString& permissions) override { implSetPosixPermissions(permissions); };
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,9 @@ public:
|
|||
CommandSupportType supportGrowOnline() const override {
|
||||
return m_Grow;
|
||||
}
|
||||
|
||||
QString posixPermissions() const override { return implPosixPermissions(); };
|
||||
void setPosixPermissions(const QString& permissions) override { implSetPosixPermissions(permissions); };
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <QStorageInfo>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
const std::vector<QColor> FileSystem::defaultColorCode =
|
||||
{
|
||||
|
@ -80,6 +81,7 @@ struct FileSystemPrivate {
|
|||
qint64 m_SectorsUsed;
|
||||
QString m_Label;
|
||||
QString m_UUID;
|
||||
QString m_posixPermissions;
|
||||
QStringList m_AvailableFeatures;
|
||||
QVariantMap m_Features;
|
||||
};
|
||||
|
@ -126,6 +128,67 @@ FileSystem::~FileSystem()
|
|||
{
|
||||
}
|
||||
|
||||
QString FileSystem::implPosixPermissions() const
|
||||
{
|
||||
return d->m_posixPermissions;
|
||||
}
|
||||
|
||||
void FileSystem::implSetPosixPermissions(const QString& permissions)
|
||||
{
|
||||
d->m_posixPermissions = permissions;
|
||||
}
|
||||
|
||||
|
||||
bool FileSystem::execChangePosixPermission(Report& report, const QString& deviceNode)
|
||||
{
|
||||
// do nothing if the posix permissions is not used here.
|
||||
if (d->m_posixPermissions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QTemporaryDir tmpDir;
|
||||
|
||||
ExternalCommand mountCmd(report, QStringLiteral("mount"),
|
||||
{ deviceNode, tmpDir.path() });
|
||||
|
||||
bool step = mountCmd.run() && mountCmd.exitCode() == 0;
|
||||
if (!step) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ExternalCommand chmodCmd(report, QStringLiteral("chmod"),
|
||||
// forcing recursive, should be empty but
|
||||
// programming is weird.
|
||||
{
|
||||
d->m_posixPermissions,
|
||||
tmpDir.path(),
|
||||
QStringLiteral("-R")
|
||||
});
|
||||
|
||||
const bool chmodStep = chmodCmd.run() && chmodCmd.exitCode() == 0;
|
||||
|
||||
ExternalCommand umountCmd(report, QStringLiteral("umount"),
|
||||
// forcing recursive, should be empty but
|
||||
// programming is weird.
|
||||
{
|
||||
deviceNode,
|
||||
});
|
||||
|
||||
const bool umountStep = umountCmd.run() && umountCmd.exitCode() == 0;
|
||||
|
||||
// we can't return false if chmodStep fails because we still need to umount
|
||||
// the drive.
|
||||
if (!chmodStep) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!umountStep) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Reads the capacity in use on this FileSystem
|
||||
@param deviceNode the device node for the Partition the FileSystem is on
|
||||
@return the used capacity in bytes or -1 in case of an error
|
||||
|
|
|
@ -113,6 +113,9 @@ protected:
|
|||
FileSystem(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type type);
|
||||
FileSystem(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, const QVariantMap& features, FileSystem::Type type);
|
||||
|
||||
QString implPosixPermissions() const;
|
||||
void implSetPosixPermissions(const QString& permissions);
|
||||
|
||||
public:
|
||||
virtual ~FileSystem();
|
||||
|
||||
|
@ -199,6 +202,14 @@ public:
|
|||
virtual SupportTool supportToolName() const;
|
||||
virtual bool supportToolFound() const;
|
||||
|
||||
virtual QString posixPermissions() const { return QString{}; };
|
||||
virtual void setPosixPermissions(const QString& permissions) { Q_UNUSED(permissions); };
|
||||
|
||||
// Tries to change the posix permission on the filesystem, if the
|
||||
// filesystem supports it. by supports I mean reimplements `posixPermissions()`
|
||||
// and setPosixPermissions.
|
||||
bool execChangePosixPermission(Report& report, const QString& deviceNode);
|
||||
|
||||
/**
|
||||
* Returns the (possibly translated) name of the type of this filesystem.
|
||||
* @see nameForType()
|
||||
|
|
|
@ -27,9 +27,11 @@ bool ChangePermissionJob::run(Report& parent)
|
|||
{
|
||||
bool rval = false;
|
||||
|
||||
auto &fs = m_Partition.fileSystem();
|
||||
|
||||
Report* report = jobStarted(parent);
|
||||
|
||||
rval = m_Partition.execChangePermission(*report);
|
||||
rval = fs.execChangePosixPermission(*report, m_Partition.deviceNode());
|
||||
|
||||
jobFinished(*report, rval);
|
||||
|
||||
|
|
Loading…
Reference in New Issue