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})
|
||||
target_link_libraries( kpmcore PUBLIC
|
||||
PRIVATE
|
||||
Qt5::Core
|
||||
PRIVATE
|
||||
Qt5::DBus
|
||||
Qt5::Gui
|
||||
KF5::I18n
|
||||
|
|
|
@ -58,18 +58,22 @@ void CoreBackend::setPartitionTableMaxPrimaries(PartitionTable& p, qint32 max_pr
|
|||
p.setMaxPrimaries(max_primaries);
|
||||
}
|
||||
|
||||
QString CoreBackend::id() {
|
||||
QString CoreBackend::id()
|
||||
{
|
||||
return d->m_id;
|
||||
}
|
||||
|
||||
QString CoreBackend::version() {
|
||||
QString CoreBackend::version()
|
||||
{
|
||||
return d->m_version;
|
||||
}
|
||||
|
||||
void CoreBackend::setId(const QString& id) {
|
||||
void CoreBackend::setId(const QString& id)
|
||||
{
|
||||
d->m_id = id;
|
||||
}
|
||||
|
||||
void CoreBackend::setVersion(const QString& version) {
|
||||
void CoreBackend::setVersion(const QString& version)
|
||||
{
|
||||
d->m_version = version;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,8 @@ CoreBackendManager* CoreBackendManager::self()
|
|||
return instance;
|
||||
}
|
||||
|
||||
CoreBackend* CoreBackendManager::backend() {
|
||||
CoreBackend* CoreBackendManager::backend()
|
||||
{
|
||||
return d->m_Backend;
|
||||
}
|
||||
|
||||
|
@ -101,11 +102,13 @@ void CoreBackendManager::stopExternalCommandHelper()
|
|||
iface.call(QStringLiteral("exit"), CoreBackendManager::self()->Uuid());
|
||||
}
|
||||
|
||||
KAuth::ExecuteJob* CoreBackendManager::job() {
|
||||
KAuth::ExecuteJob* CoreBackendManager::job()
|
||||
{
|
||||
return d->m_job;
|
||||
}
|
||||
|
||||
QString& CoreBackendManager::Uuid() {
|
||||
QString& CoreBackendManager::Uuid()
|
||||
{
|
||||
return d->m_Uuid;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,25 +34,31 @@
|
|||
static void parseFsSpec(const QString& m_fsSpec, FstabEntryType& m_entryType, QString& m_deviceNode);
|
||||
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)
|
||||
: m_fsSpec(fsSpec)
|
||||
, m_mountPoint(mountPoint)
|
||||
, m_type(type)
|
||||
, m_dumpFreq(dumpFreq)
|
||||
, m_passNumber(passNumber)
|
||||
, m_comment(comment)
|
||||
struct FstabEntryPrivate
|
||||
{
|
||||
m_options = options.split(QLatin1Char(','));
|
||||
parseFsSpec(m_fsSpec, m_entryType, m_deviceNode);
|
||||
}
|
||||
QString m_fsSpec;
|
||||
QString m_deviceNode;
|
||||
QString m_mountPoint;
|
||||
QString m_type;
|
||||
QStringList m_options;
|
||||
int m_dumpFreq;
|
||||
int m_passNumber;
|
||||
QString m_comment;
|
||||
FstabEntryType m_entryType;
|
||||
};
|
||||
|
||||
/**
|
||||
@param s the new value for the fs_spec field of fstab entry
|
||||
*/
|
||||
void FstabEntry::setFsSpec(const QString& s)
|
||||
FstabEntry::FstabEntry(const QString& fsSpec, const QString& mountPoint, const QString& type, const QString& options, int dumpFreq, int passNumber, const QString& comment) :
|
||||
d(std::make_unique<FstabEntryPrivate>())
|
||||
{
|
||||
m_fsSpec = s;
|
||||
parseFsSpec(m_fsSpec, m_entryType, m_deviceNode);
|
||||
d->m_fsSpec = fsSpec;
|
||||
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 )
|
||||
|
@ -66,7 +72,7 @@ FstabEntryList readFstabEntries( const QString& fstabPath )
|
|||
{
|
||||
QString line = rawLine.trimmed();
|
||||
if ( line.startsWith( QLatin1Char('#') ) || line.isEmpty()) {
|
||||
fstabEntries.append( { {}, {}, {}, {}, {}, {}, line } );
|
||||
fstabEntries.push_back( { {}, {}, {}, {}, {}, {}, line } );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -83,27 +89,98 @@ FstabEntryList readFstabEntries( const QString& fstabPath )
|
|||
// (#) comment (optional).
|
||||
switch (splitLine.length()) {
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
default:
|
||||
fstabEntries.append( { {}, {}, {}, {}, {}, {}, QLatin1Char('#') + line } );
|
||||
fstabEntries.push_back( { {}, {}, {}, {}, {}, {}, QLatin1Char('#') + line } );
|
||||
}
|
||||
}
|
||||
|
||||
fstabFile.close();
|
||||
if (fstabEntries.last().entryType() == comment && fstabEntries.last().comment().isEmpty())
|
||||
fstabEntries.removeLast();
|
||||
if (fstabEntries.back().entryType() == comment && fstabEntries.back().comment().isEmpty())
|
||||
fstabEntries.pop_back();
|
||||
}
|
||||
|
||||
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 mountPoints;
|
||||
|
@ -177,7 +254,7 @@ static void writeEntry(QFile& output, const FstabEntry& entry)
|
|||
<< entry.comment() << "\n";
|
||||
}
|
||||
|
||||
bool writeMountpoints(const FstabEntryList fstabEntries, const QString& filename)
|
||||
bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename)
|
||||
{
|
||||
QTemporaryFile out;
|
||||
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 *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -20,9 +20,13 @@
|
|||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
struct FstabEntryPrivate;
|
||||
|
||||
enum FstabEntryType { deviceNode, uuid, label, partlabel, partuuid, comment };
|
||||
|
||||
/** Base class for fstab handling.
|
||||
|
@ -37,63 +41,84 @@ class LIBKPMCORE_EXPORT FstabEntry
|
|||
public:
|
||||
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 */
|
||||
}
|
||||
const QString& deviceNode() 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 fs_spec field of fstab entry
|
||||
*/
|
||||
const QString& fsSpec() const;
|
||||
|
||||
/**
|
||||
* @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 setMountPoint(const QString& s) {
|
||||
m_mountPoint = s; /**< @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 setDumpFreq(int s) {
|
||||
m_dumpFreq = s; /**< @param s the new value for the dump frequency */
|
||||
}
|
||||
void setPassNumber(int s) {
|
||||
m_passNumber = s; /**< @param s the new value for the pass number */
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s the new value for the mount point
|
||||
*/
|
||||
void setMountPoint(const QString& s);
|
||||
|
||||
/**
|
||||
* @param s the new list with the mount options
|
||||
*/
|
||||
void setOptions(const QStringList& s);
|
||||
|
||||
/**
|
||||
* @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:
|
||||
QString m_fsSpec;
|
||||
QString m_deviceNode;
|
||||
QString m_mountPoint;
|
||||
QString m_type;
|
||||
QStringList m_options;
|
||||
int m_dumpFreq;
|
||||
int m_passNumber;
|
||||
QString m_comment;
|
||||
FstabEntryType m_entryType;
|
||||
std::shared_ptr<FstabEntryPrivate> d;
|
||||
};
|
||||
|
||||
typedef QList<FstabEntry> FstabEntryList;
|
||||
|
||||
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 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
|
||||
|
|
Loading…
Reference in New Issue