d-pointerize FstabEntry class
This commit is contained in:
parent
7ed6657e30
commit
398e9c3df5
|
@ -40,8 +40,8 @@ ki18n_wrap_ui(kpmcore_SRCS ${gui_UIFILES})
|
||||||
|
|
||||||
add_library(kpmcore SHARED ${kpmcore_SRCS})
|
add_library(kpmcore SHARED ${kpmcore_SRCS})
|
||||||
target_link_libraries( kpmcore PUBLIC
|
target_link_libraries( kpmcore PUBLIC
|
||||||
PRIVATE
|
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
|
PRIVATE
|
||||||
Qt5::DBus
|
Qt5::DBus
|
||||||
Qt5::Gui
|
Qt5::Gui
|
||||||
KF5::I18n
|
KF5::I18n
|
||||||
|
|
|
@ -58,18 +58,22 @@ void CoreBackend::setPartitionTableMaxPrimaries(PartitionTable& p, qint32 max_pr
|
||||||
p.setMaxPrimaries(max_primaries);
|
p.setMaxPrimaries(max_primaries);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CoreBackend::id() {
|
QString CoreBackend::id()
|
||||||
|
{
|
||||||
return d->m_id;
|
return d->m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CoreBackend::version() {
|
QString CoreBackend::version()
|
||||||
|
{
|
||||||
return d->m_version;
|
return d->m_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreBackend::setId(const QString& id) {
|
void CoreBackend::setId(const QString& id)
|
||||||
|
{
|
||||||
d->m_id = id;
|
d->m_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreBackend::setVersion(const QString& version) {
|
void CoreBackend::setVersion(const QString& version)
|
||||||
|
{
|
||||||
d->m_version = version;
|
d->m_version = version;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,8 @@ CoreBackendManager* CoreBackendManager::self()
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreBackend* CoreBackendManager::backend() {
|
CoreBackend* CoreBackendManager::backend()
|
||||||
|
{
|
||||||
return d->m_Backend;
|
return d->m_Backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +102,13 @@ void CoreBackendManager::stopExternalCommandHelper()
|
||||||
iface.call(QStringLiteral("exit"), CoreBackendManager::self()->Uuid());
|
iface.call(QStringLiteral("exit"), CoreBackendManager::self()->Uuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
KAuth::ExecuteJob* CoreBackendManager::job() {
|
KAuth::ExecuteJob* CoreBackendManager::job()
|
||||||
|
{
|
||||||
return d->m_job;
|
return d->m_job;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString& CoreBackendManager::Uuid() {
|
QString& CoreBackendManager::Uuid()
|
||||||
|
{
|
||||||
return d->m_Uuid;
|
return d->m_Uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,25 +34,31 @@
|
||||||
static void parseFsSpec(const QString& m_fsSpec, FstabEntryType& m_entryType, QString& m_deviceNode);
|
static void parseFsSpec(const QString& m_fsSpec, FstabEntryType& m_entryType, QString& m_deviceNode);
|
||||||
static QString findBlkIdDevice(const char *token, const QString& value);
|
static QString findBlkIdDevice(const char *token, const QString& value);
|
||||||
|
|
||||||
FstabEntry::FstabEntry(const QString& fsSpec, const QString& mountPoint, const QString& type, const QString& options, int dumpFreq, int passNumber, const QString& comment)
|
struct FstabEntryPrivate
|
||||||
: m_fsSpec(fsSpec)
|
|
||||||
, m_mountPoint(mountPoint)
|
|
||||||
, m_type(type)
|
|
||||||
, m_dumpFreq(dumpFreq)
|
|
||||||
, m_passNumber(passNumber)
|
|
||||||
, m_comment(comment)
|
|
||||||
{
|
{
|
||||||
m_options = options.split(QLatin1Char(','));
|
QString m_fsSpec;
|
||||||
parseFsSpec(m_fsSpec, m_entryType, m_deviceNode);
|
QString m_deviceNode;
|
||||||
}
|
QString m_mountPoint;
|
||||||
|
QString m_type;
|
||||||
|
QStringList m_options;
|
||||||
|
int m_dumpFreq;
|
||||||
|
int m_passNumber;
|
||||||
|
QString m_comment;
|
||||||
|
FstabEntryType m_entryType;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
FstabEntry::FstabEntry(const QString& fsSpec, const QString& mountPoint, const QString& type, const QString& options, int dumpFreq, int passNumber, const QString& comment) :
|
||||||
@param s the new value for the fs_spec field of fstab entry
|
d(std::make_unique<FstabEntryPrivate>())
|
||||||
*/
|
|
||||||
void FstabEntry::setFsSpec(const QString& s)
|
|
||||||
{
|
{
|
||||||
m_fsSpec = s;
|
d->m_fsSpec = fsSpec;
|
||||||
parseFsSpec(m_fsSpec, m_entryType, m_deviceNode);
|
d->m_mountPoint = mountPoint;
|
||||||
|
d->m_type = type;
|
||||||
|
d->m_dumpFreq = dumpFreq;
|
||||||
|
d->m_passNumber = passNumber;
|
||||||
|
d->m_comment = comment;
|
||||||
|
|
||||||
|
d->m_options = options.split(QLatin1Char(','));
|
||||||
|
parseFsSpec(d->m_fsSpec, d->m_entryType, d->m_deviceNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
FstabEntryList readFstabEntries( const QString& fstabPath )
|
FstabEntryList readFstabEntries( const QString& fstabPath )
|
||||||
|
@ -66,7 +72,7 @@ FstabEntryList readFstabEntries( const QString& fstabPath )
|
||||||
{
|
{
|
||||||
QString line = rawLine.trimmed();
|
QString line = rawLine.trimmed();
|
||||||
if ( line.startsWith( QLatin1Char('#') ) || line.isEmpty()) {
|
if ( line.startsWith( QLatin1Char('#') ) || line.isEmpty()) {
|
||||||
fstabEntries.append( { {}, {}, {}, {}, {}, {}, line } );
|
fstabEntries.push_back( { {}, {}, {}, {}, {}, {}, line } );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,27 +89,98 @@ FstabEntryList readFstabEntries( const QString& fstabPath )
|
||||||
// (#) comment (optional).
|
// (#) comment (optional).
|
||||||
switch (splitLine.length()) {
|
switch (splitLine.length()) {
|
||||||
case 4:
|
case 4:
|
||||||
fstabEntries.append( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3) } );
|
fstabEntries.push_back( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3) } );
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
fstabEntries.append( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt() } );
|
fstabEntries.push_back( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt() } );
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
fstabEntries.append( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt(), splitLine.at(5).toInt(), comment.isEmpty() ? QString() : QLatin1Char('#') + comment } );
|
fstabEntries.push_back( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt(), splitLine.at(5).toInt(), comment.isEmpty() ? QString() : QLatin1Char('#') + comment } );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fstabEntries.append( { {}, {}, {}, {}, {}, {}, QLatin1Char('#') + line } );
|
fstabEntries.push_back( { {}, {}, {}, {}, {}, {}, QLatin1Char('#') + line } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fstabFile.close();
|
fstabFile.close();
|
||||||
if (fstabEntries.last().entryType() == comment && fstabEntries.last().comment().isEmpty())
|
if (fstabEntries.back().entryType() == comment && fstabEntries.back().comment().isEmpty())
|
||||||
fstabEntries.removeLast();
|
fstabEntries.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
return fstabEntries;
|
return fstabEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FstabEntry::setFsSpec(const QString& s)
|
||||||
|
{
|
||||||
|
d->m_fsSpec = s;
|
||||||
|
parseFsSpec(d->m_fsSpec, d->m_entryType, d->m_deviceNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& FstabEntry::fsSpec() const
|
||||||
|
{
|
||||||
|
return d->m_fsSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& FstabEntry::deviceNode() const
|
||||||
|
{
|
||||||
|
return d->m_deviceNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& FstabEntry::mountPoint() const
|
||||||
|
{
|
||||||
|
return d->m_mountPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& FstabEntry::type() const
|
||||||
|
{
|
||||||
|
return d->m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList& FstabEntry::options() const
|
||||||
|
{
|
||||||
|
return d->m_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FstabEntry::dumpFreq() const
|
||||||
|
{
|
||||||
|
return d->m_dumpFreq;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FstabEntry::passNumber() const
|
||||||
|
{
|
||||||
|
return d->m_passNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& FstabEntry::comment() const
|
||||||
|
{
|
||||||
|
return d->m_comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
FstabEntryType FstabEntry::entryType() const
|
||||||
|
{
|
||||||
|
return d->m_entryType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FstabEntry::setMountPoint(const QString& s)
|
||||||
|
{
|
||||||
|
d->m_mountPoint = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FstabEntry::setOptions(const QStringList& s)
|
||||||
|
{
|
||||||
|
d->m_options = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FstabEntry::setDumpFreq(int s)
|
||||||
|
{
|
||||||
|
d->m_dumpFreq = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FstabEntry::setPassNumber(int s)
|
||||||
|
{
|
||||||
|
d->m_passNumber = s;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath)
|
QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath)
|
||||||
{
|
{
|
||||||
QStringList mountPoints;
|
QStringList mountPoints;
|
||||||
|
@ -177,7 +254,7 @@ static void writeEntry(QFile& output, const FstabEntry& entry)
|
||||||
<< entry.comment() << "\n";
|
<< entry.comment() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeMountpoints(const FstabEntryList fstabEntries, const QString& filename)
|
bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename)
|
||||||
{
|
{
|
||||||
QTemporaryFile out;
|
QTemporaryFile out;
|
||||||
out.setAutoRemove(false);
|
out.setAutoRemove(false);
|
||||||
|
|
125
src/core/fstab.h
125
src/core/fstab.h
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* Copyright (C) 2017 by Andrius Štikonas <andrius@stikonas.eu> *
|
* Copyright (C) 2017-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
@ -20,9 +20,13 @@
|
||||||
|
|
||||||
#include "util/libpartitionmanagerexport.h"
|
#include "util/libpartitionmanagerexport.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
struct FstabEntryPrivate;
|
||||||
|
|
||||||
enum FstabEntryType { deviceNode, uuid, label, partlabel, partuuid, comment };
|
enum FstabEntryType { deviceNode, uuid, label, partlabel, partuuid, comment };
|
||||||
|
|
||||||
/** Base class for fstab handling.
|
/** Base class for fstab handling.
|
||||||
|
@ -37,63 +41,84 @@ class LIBKPMCORE_EXPORT FstabEntry
|
||||||
public:
|
public:
|
||||||
FstabEntry(const QString& fsSpec, const QString& mountPoint, const QString& type, const QString& options, int dumpFreq = 0, int passNumber = 0, const QString& comment = QString());
|
FstabEntry(const QString& fsSpec, const QString& mountPoint, const QString& type, const QString& options, int dumpFreq = 0, int passNumber = 0, const QString& comment = QString());
|
||||||
|
|
||||||
const QString& fsSpec() const {
|
/**
|
||||||
return m_fsSpec; /**< @return the fs_spec field of fstab entry */
|
* @return the fs_spec field of fstab entry
|
||||||
}
|
*/
|
||||||
const QString& deviceNode() const {
|
const QString& fsSpec() const;
|
||||||
return m_deviceNode; /**< @return the device node corresponding to fs_spec entry */
|
|
||||||
}
|
|
||||||
const QString& mountPoint() const {
|
|
||||||
return m_mountPoint; /**< @return the mount point (target) for the file system */
|
|
||||||
}
|
|
||||||
const QString& type() const {
|
|
||||||
return m_type; /**< @return the type of the file system */
|
|
||||||
}
|
|
||||||
const QStringList& options() const {
|
|
||||||
return m_options; /**< @return the mount options associated with the file system */
|
|
||||||
}
|
|
||||||
int dumpFreq() const {
|
|
||||||
return m_dumpFreq; /**< @return the fs_freq field of fstab entry */
|
|
||||||
}
|
|
||||||
int passNumber() const {
|
|
||||||
return m_passNumber; /**< @return the fs_passno field of fstab entry */
|
|
||||||
}
|
|
||||||
const QString& comment() const {
|
|
||||||
return m_comment; /**< @return commented part of the line in fstab file */
|
|
||||||
}
|
|
||||||
FstabEntryType entryType() const {
|
|
||||||
return m_entryType; /**< @return the type of fstab entry, e.g. device node or UUID or comment only */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the device node corresponding to fs_spec entry
|
||||||
|
*/
|
||||||
|
const QString& deviceNode() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the mount point (target) for the file system
|
||||||
|
*/
|
||||||
|
const QString& mountPoint() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the type of the file system
|
||||||
|
*/
|
||||||
|
const QString& type() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the mount options associated with the file system
|
||||||
|
*/
|
||||||
|
const QStringList& options() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the fs_freq field of fstab entry
|
||||||
|
*/
|
||||||
|
int dumpFreq() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the fs_passno field of fstab entry
|
||||||
|
*/
|
||||||
|
int passNumber() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return commented part of the line in fstab file
|
||||||
|
*/
|
||||||
|
const QString& comment() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the type of fstab entry, e.g. device node or UUID or comment only
|
||||||
|
*/
|
||||||
|
FstabEntryType entryType() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param s the new value for the fs_spec field of fstab entry
|
||||||
|
*/
|
||||||
void setFsSpec(const QString& s);
|
void setFsSpec(const QString& s);
|
||||||
void setMountPoint(const QString& s) {
|
|
||||||
m_mountPoint = s; /**< @param s the new value for the mount point */
|
/**
|
||||||
}
|
* @param s the new value for the mount point
|
||||||
void setOptions(const QStringList& s) {
|
*/
|
||||||
m_options = s; /**< @param s the new list with the mount options */
|
void setMountPoint(const QString& s);
|
||||||
}
|
|
||||||
void setDumpFreq(int s) {
|
/**
|
||||||
m_dumpFreq = s; /**< @param s the new value for the dump frequency */
|
* @param s the new list with the mount options
|
||||||
}
|
*/
|
||||||
void setPassNumber(int s) {
|
void setOptions(const QStringList& s);
|
||||||
m_passNumber = s; /**< @param s the new value for the pass number */
|
|
||||||
}
|
/**
|
||||||
|
* @param s the new value for the dump frequency
|
||||||
|
*/
|
||||||
|
void setDumpFreq(int s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param s the new value for the pass number
|
||||||
|
*/
|
||||||
|
void setPassNumber(int s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_fsSpec;
|
std::shared_ptr<FstabEntryPrivate> d;
|
||||||
QString m_deviceNode;
|
|
||||||
QString m_mountPoint;
|
|
||||||
QString m_type;
|
|
||||||
QStringList m_options;
|
|
||||||
int m_dumpFreq;
|
|
||||||
int m_passNumber;
|
|
||||||
QString m_comment;
|
|
||||||
FstabEntryType m_entryType;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QList<FstabEntry> FstabEntryList;
|
typedef QList<FstabEntry> FstabEntryList;
|
||||||
|
|
||||||
LIBKPMCORE_EXPORT FstabEntryList readFstabEntries(const QString& fstabPath = QStringLiteral("/etc/fstab"));
|
LIBKPMCORE_EXPORT FstabEntryList readFstabEntries(const QString& fstabPath = QStringLiteral("/etc/fstab"));
|
||||||
LIBKPMCORE_EXPORT QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath = QStringLiteral("/etc/fstab"));
|
LIBKPMCORE_EXPORT QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath = QStringLiteral("/etc/fstab"));
|
||||||
LIBKPMCORE_EXPORT bool writeMountpoints(const FstabEntryList fstabEntries, const QString& filename = QStringLiteral("/etc/fstab"));
|
LIBKPMCORE_EXPORT bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename = QStringLiteral("/etc/fstab"));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue