10#include "../utils_p.h"
18#include "kiocoredebug.h"
20#include <KConfigGroup>
23class Q_DECL_HIDDEN
KNFSShare::KNFSSharePrivate
26 explicit KNFSSharePrivate(
KNFSShare *parent);
28 void slotFileChange(
const QString &);
30 bool readExportsFile();
31 bool findExportsFile();
38KNFSShare::KNFSSharePrivate::KNFSSharePrivate(
KNFSShare *parent)
41 if (findExportsFile()) {
52bool KNFSShare::KNFSSharePrivate::findExportsFile()
54 KConfig knfsshare(QStringLiteral(
"knfsshare"));
55 KConfigGroup config(&knfsshare, QStringLiteral(
"General"));
56 exportsFile = config.readPathEntry(
"exportsFile",
QString());
63 exportsFile = QStringLiteral(
"/etc/exports");
69 config.writeEntry(
"exportsFile", exportsFile);
77bool KNFSShare::KNFSSharePrivate::readExportsFile()
84 qCWarning(KIO_CORE) <<
"KNFSShare: Could not open" << exportsFile;
92 bool continuedLine =
false;
99 completeLine += currentLine;
100 continuedLine =
false;
102 completeLine = currentLine;
107 continuedLine =
true;
109 completeLine.
chop(1);
124 qCWarning(KIO_CORE) <<
"KNFSShare: Parse error: Missing quotation mark:" << completeLine;
127 path = completeLine.
mid(1, i - 1);
146 Utils::appendSlash(path);
147 sharedPaths.insert(path);
154KNFSShare::KNFSShare()
155 : d(new KNFSSharePrivate(this))
158 KDirWatch::self()->addFile(d->exportsFile);
159 connect(KDirWatch::self(), &KDirWatch::dirty, this, [this](const QString &path) {
160 d->slotFileChange(path);
173 return d->sharedPaths.contains(Utils::slashAppended(path));
178 return d->sharedPaths.values();
183 return d->exportsFile;
186void KNFSShare::KNFSSharePrivate::slotFileChange(
const QString &path)
188 if (path == exportsFile) {
195class KNFSShareSingleton
201Q_GLOBAL_STATIC(KNFSShareSingleton, _instance)
208#include "moc_knfsshare.cpp"
Similar functionality like KFileShare, but works only for NFS and do not need any suid script.
QString exportsPath() const
Returns the path to the used exports file, or null if no exports file was found.
void changed()
Emitted when the /etc/exports file has changed.
~KNFSShare() override
KNFSShare destructor.
static KNFSShare * instance()
Returns the one and only instance of KNFSShare.
bool isDirectoryShared(const QString &path) const
Whether or not the given path is shared by NFS.
QStringList sharedDirectories() const
Returns a list of all directories shared by NFS.
QString path(const QString &relativePath)
bool exists() const const
bool exists() const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(qsizetype n) const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString trimmed() const const