22#include <QtCore/QFile>
23#include <QtCore/QMutableStringListIterator>
24#include <QtCore/QTextIStream>
32class KNFSShare::KNFSSharePrivate
37 void _k_slotFileChange(
const QString&);
39 bool readExportsFile();
40 bool findExportsFile();
47KNFSShare::KNFSSharePrivate::KNFSSharePrivate(
KNFSShare *parent )
50 if (findExportsFile())
60bool KNFSShare::KNFSSharePrivate::findExportsFile()
64 exportsFile =
config.readPathEntry(
"exportsFile", QString());
66 if ( QFile::exists(exportsFile) )
69 if ( QFile::exists(
"/etc/exports") )
70 exportsFile =
"/etc/exports";
72 kDebug(7000) <<
"Could not find exports file! /etc/exports doesn't exist. Configure it in share/config/knfsshare, [General], exportsFile=....";
76 config.writeEntry(
"exportsFile",exportsFile);
84bool KNFSShare::KNFSSharePrivate::readExportsFile()
90 if (!
f.open(QIODevice::ReadOnly)) {
91 kError() <<
"KNFSShare: Could not open" << exportsFile;
99 bool continuedLine =
false;
100 QString completeLine;
104 QString currentLine = s.readLine().trimmed();
107 completeLine += currentLine;
108 continuedLine =
false;
111 completeLine = currentLine;
114 if ( completeLine.endsWith(QLatin1Char(
'\\')) )
116 continuedLine =
true;
118 completeLine.chop(1);
123 if (completeLine.startsWith(QLatin1Char(
'#')) || completeLine.isEmpty())
131 if ( completeLine[0] == QLatin1Char(
'\"') ) {
132 int i = completeLine.indexOf(QLatin1Char(
'"'), 1);
134 kError() <<
"KNFSShare: Parse error: Missing quotation mark:" << completeLine;
137 path = completeLine.mid(1,i-1);
140 int i = completeLine.indexOf(QLatin1Char(
' '));
142 i = completeLine.indexOf(QLatin1Char(
'\t'));
147 path = completeLine.left(i);
153 if (!path.isEmpty()) {
155 if ( !path.endsWith(QLatin1Char(
'/')) )
156 path += QLatin1Char(
'/');
158 sharedPaths.insert(path);
165KNFSShare::KNFSShare()
166 : d(new KNFSSharePrivate(this))
168 if (QFile::exists(d->exportsFile)) {
171 SLOT(_k_slotFileChange(QString)));
189 QString fixedPath = path;
190 if ( path[path.length()-1] !=
'/' )
193 return d->sharedPaths.contains(fixedPath);
198 return d->sharedPaths.values();
203 return d->exportsFile;
208void KNFSShare::KNFSSharePrivate::_k_slotFileChange(
const QString & path )
210 if (path == exportsFile)
223#include "knfsshare.moc"
void addFile(const QString &file)
static KDirWatch * self()
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.
static KNFSShare * instance()
Returns the one and only instance of KNFSShare.
virtual ~KNFSShare()
KNFSShare destructor.
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.
static quint32 f(DES_KEY *key, quint32 r, char *subkey)
#define K_GLOBAL_STATIC(TYPE, NAME)
KSharedConfigPtr config()