21 #include <tqtextstream.h>
23 #include <kdirwatch.h>
24 #include <kstaticdeleter.h>
26 #include <tdeconfig.h>
28 #include "knfsshare.h"
30 class KNFSSharePrivate
35 bool readExportsFile();
36 bool findExportsFile();
38 TQDict<bool> sharedPaths;
42 KNFSSharePrivate::KNFSSharePrivate()
44 if (findExportsFile())
54 bool KNFSSharePrivate::findExportsFile() {
55 TDEConfig config(
"knfsshare");
56 config.setGroup(
"General");
57 exportsFile = config.readPathEntry(
"exportsFile");
59 if ( TQFile::exists(exportsFile) )
62 if ( TQFile::exists(
"/etc/exports") )
63 exportsFile =
"/etc/exports";
65 kdDebug(7000) <<
"KNFSShare: Could not found exports file!" << endl;
69 config.writeEntry(
"exportsFile",exportsFile);
77 bool KNFSSharePrivate::readExportsFile() {
78 TQFile f(exportsFile);
80 kdDebug(7000) <<
"KNFSShare::readExportsFile " << exportsFile << endl;
82 if (!f.open(IO_ReadOnly)) {
83 kdError() <<
"KNFSShare: Could not open " << exportsFile << endl;
92 bool continuedLine =
false;
93 TQString completeLine;
97 TQString currentLine = s.readLine().stripWhiteSpace();
100 completeLine += currentLine;
101 continuedLine =
false;
104 completeLine = currentLine;
107 if ( completeLine[completeLine.length()-1] ==
'\\' )
109 continuedLine =
true;
111 completeLine.truncate( completeLine.length()-1 );
116 if (completeLine.isEmpty() ||
117 '#' == completeLine[0])
125 if ( completeLine[0] ==
'"' ) {
126 int i = completeLine.find(
'"',1);
128 kdError() <<
"KNFSShare: Parse error: Missing quotation mark: " << completeLine << endl;
131 path = completeLine.mid(1,i-1);
134 int i = completeLine.find(
' ');
136 i = completeLine.find(
'\t');
141 path = completeLine.left(i);
145 kdDebug(7000) <<
"KNFSShare: Found path: " << path << endl;
148 if ( path[path.length()-1] !=
'/' )
152 sharedPaths.insert(path,&b);
161 KNFSShare::KNFSShare() {
162 d =
new KNFSSharePrivate();
163 if (TQFile::exists(d->exportsFile)) {
166 TQ_SLOT(slotFileChange(
const TQString&)));
171 if (TQFile::exists(d->exportsFile)) {
179 TQString fixedPath = path;
180 if ( path[path.length()-1] !=
'/' )
183 return d->sharedPaths.find(fixedPath) != 0;
188 TQDictIterator<bool> it(d->sharedPaths);
189 for( ; it.current(); ++it )
190 result << it.currentKey();
196 return d->exportsFile;
201 void KNFSShare::slotFileChange(
const TQString & path ) {
202 if (path == d->exportsFile)
203 d->readExportsFile();
209 static KStaticDeleter<KNFSShare> ksdNFSShare;
213 _instance = ksdNFSShare.setObject(_instance,
new KNFSShare());
218 #include "knfsshare.moc"
static KDirWatch * self()
The KDirWatch instance usually globally used in an application.
void addFile(const TQString &file)
Adds a file to be watched.
void removeFile(const TQString &file)
Removes a file from the list of watched files.
Similar functionality like KFileShare, but works only for NFS and do not need any suid script.
void changed()
Emitted when the /etc/exports file has changed.
bool isDirectoryShared(const TQString &path) const
Wether or not the given path is shared by NFS.
static KNFSShare * instance()
Returns the one and only instance of KNFSShare.
TQStringList sharedDirectories() const
Returns a list of all directories shared by NFS.
virtual ~KNFSShare()
KNFSShare destructor.
TQString exportsPath() const
Returns the path to the used exports file, or null if no exports file was found.