|
|
@ -60,6 +60,7 @@
|
|
|
|
#include <tdeglobal.h>
|
|
|
|
#include <tdeglobal.h>
|
|
|
|
#include <kstaticdeleter.h>
|
|
|
|
#include <kstaticdeleter.h>
|
|
|
|
#include <kde_file.h>
|
|
|
|
#include <kde_file.h>
|
|
|
|
|
|
|
|
#include <kurl.h>
|
|
|
|
|
|
|
|
|
|
|
|
// debug
|
|
|
|
// debug
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
@ -429,9 +430,9 @@ void KDirWatchPrivate::slotActivated()
|
|
|
|
kdDebug(7001) << "-->got deleteself signal for " << e->path << endl;
|
|
|
|
kdDebug(7001) << "-->got deleteself signal for " << e->path << endl;
|
|
|
|
e->m_status = NonExistent;
|
|
|
|
e->m_status = NonExistent;
|
|
|
|
if (e->isDir)
|
|
|
|
if (e->isDir)
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true);
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true);
|
|
|
|
addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( event->mask & IN_IGNORED ) {
|
|
|
|
if ( event->mask & IN_IGNORED ) {
|
|
|
|
e->wd = 0;
|
|
|
|
e->wd = 0;
|
|
|
@ -439,10 +440,10 @@ void KDirWatchPrivate::slotActivated()
|
|
|
|
if ( event->mask & (IN_CREATE|IN_MOVED_TO) ) {
|
|
|
|
if ( event->mask & (IN_CREATE|IN_MOVED_TO) ) {
|
|
|
|
Entry *sub_entry = e->m_entries.first();
|
|
|
|
Entry *sub_entry = e->m_entries.first();
|
|
|
|
for(;sub_entry; sub_entry = e->m_entries.next())
|
|
|
|
for(;sub_entry; sub_entry = e->m_entries.next())
|
|
|
|
if (sub_entry->path == e->path + "/" + path) break;
|
|
|
|
if (sub_entry->path == e->path.path() + "/" + path) break;
|
|
|
|
|
|
|
|
|
|
|
|
if (sub_entry /*&& sub_entry->isDir*/) {
|
|
|
|
if (sub_entry /*&& sub_entry->isDir*/) {
|
|
|
|
removeEntry(0,e->path, sub_entry);
|
|
|
|
removeEntry(0,e->path.path(), sub_entry);
|
|
|
|
KDE_struct_stat stat_buf;
|
|
|
|
KDE_struct_stat stat_buf;
|
|
|
|
TQCString tpath = TQFile::encodeName(path);
|
|
|
|
TQCString tpath = TQFile::encodeName(path);
|
|
|
|
KDE_stat(tpath, &stat_buf);
|
|
|
|
KDE_stat(tpath, &stat_buf);
|
|
|
@ -539,19 +540,19 @@ int KDirWatchPrivate::Entry::clients()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KDirWatchPrivate::Entry* KDirWatchPrivate::entry(const TQString& _path)
|
|
|
|
KDirWatchPrivate::Entry* KDirWatchPrivate::entry(const KURL& _path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// we only support absolute paths
|
|
|
|
// we only support absolute paths
|
|
|
|
if (TQDir::isRelativePath(_path)) {
|
|
|
|
if (TQDir::isRelativePath(_path.path())) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TQString path = _path;
|
|
|
|
TQString path = _path.path();
|
|
|
|
|
|
|
|
|
|
|
|
if ( path.length() > 1 && path.right(1) == "/" )
|
|
|
|
if ( path.length() > 1 && path.right(1) == "/" )
|
|
|
|
path.truncate( path.length() - 1 );
|
|
|
|
path.truncate( path.length() - 1 );
|
|
|
|
|
|
|
|
|
|
|
|
EntryMap::Iterator it = m_mapEntries.find( path );
|
|
|
|
EntryMap::Iterator it = m_mapEntries.find( _path );
|
|
|
|
if ( it == m_mapEntries.end() )
|
|
|
|
if ( it == m_mapEntries.end() )
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -588,10 +589,10 @@ bool KDirWatchPrivate::useFAM(Entry* e)
|
|
|
|
if (e->isDir) {
|
|
|
|
if (e->isDir) {
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
// If the directory does not exist we watch the parent directory
|
|
|
|
// If the directory does not exist we watch the parent directory
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true);
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
int res =FAMMonitorDirectory(&fc, TQFile::encodeName(e->path),
|
|
|
|
int res =FAMMonitorDirectory(&fc, TQFile::encodeName(e->path.path()),
|
|
|
|
&(e->fr), e);
|
|
|
|
&(e->fr), e);
|
|
|
|
if (res<0) {
|
|
|
|
if (res<0) {
|
|
|
|
e->m_mode = UnknownMode;
|
|
|
|
e->m_mode = UnknownMode;
|
|
|
@ -600,16 +601,16 @@ bool KDirWatchPrivate::useFAM(Entry* e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kdDebug(7001) << " Setup FAM (Req "
|
|
|
|
kdDebug(7001) << " Setup FAM (Req "
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< ") for " << e->path << endl;
|
|
|
|
<< ") for " << e->path.path() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
// If the file does not exist we watch the directory
|
|
|
|
// If the file does not exist we watch the directory
|
|
|
|
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true);
|
|
|
|
addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
int res = FAMMonitorFile(&fc, TQFile::encodeName(e->path),
|
|
|
|
int res = FAMMonitorFile(&fc, TQFile::encodeName(e->path.path()),
|
|
|
|
&(e->fr), e);
|
|
|
|
&(e->fr), e);
|
|
|
|
if (res<0) {
|
|
|
|
if (res<0) {
|
|
|
|
e->m_mode = UnknownMode;
|
|
|
|
e->m_mode = UnknownMode;
|
|
|
@ -619,7 +620,7 @@ bool KDirWatchPrivate::useFAM(Entry* e)
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << " Setup FAM (Req "
|
|
|
|
kdDebug(7001) << " Setup FAM (Req "
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< ") for " << e->path << endl;
|
|
|
|
<< ") for " << e->path.path() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -644,7 +645,7 @@ bool KDirWatchPrivate::useDNotify(Entry* e)
|
|
|
|
|
|
|
|
|
|
|
|
if (e->isDir) {
|
|
|
|
if (e->isDir) {
|
|
|
|
if (e->m_status == Normal) {
|
|
|
|
if (e->m_status == Normal) {
|
|
|
|
int fd = KDE_open(TQFile::encodeName(e->path).data(), O_RDONLY);
|
|
|
|
int fd = KDE_open(TQFile::encodeName(e->path.path()).data(), O_RDONLY);
|
|
|
|
// Migrate fd to somewhere above 128. Some libraries have
|
|
|
|
// Migrate fd to somewhere above 128. Some libraries have
|
|
|
|
// constructs like:
|
|
|
|
// constructs like:
|
|
|
|
// fd = socket(...)
|
|
|
|
// fd = socket(...)
|
|
|
@ -688,16 +689,16 @@ bool KDirWatchPrivate::useDNotify(Entry* e)
|
|
|
|
e->dn_fd = fd;
|
|
|
|
e->dn_fd = fd;
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << " Setup DNotify (fd " << fd
|
|
|
|
kdDebug(7001) << " Setup DNotify (fd " << fd
|
|
|
|
<< ") for " << e->path << endl;
|
|
|
|
<< ") for " << e->path.path() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // NotExisting
|
|
|
|
else { // NotExisting
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true);
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // File
|
|
|
|
else { // File
|
|
|
|
// we always watch the directory (DNOTIFY can't watch files alone)
|
|
|
|
// we always watch the directory (DNOTIFY can't watch files alone)
|
|
|
|
// this notifies us about changes of files therein
|
|
|
|
// this notifies us about changes of files therein
|
|
|
|
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true);
|
|
|
|
addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -726,14 +727,14 @@ bool KDirWatchPrivate::useINotify( Entry* e )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( ( e->wd = inotify_add_watch( m_inotify_fd,
|
|
|
|
if ( ( e->wd = inotify_add_watch( m_inotify_fd,
|
|
|
|
TQFile::encodeName( e->path ), mask) ) > 0 )
|
|
|
|
TQFile::encodeName( e->path.path() ), mask) ) > 0 )
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
if ( e->m_status == NonExistent ) {
|
|
|
|
if ( e->m_status == NonExistent ) {
|
|
|
|
if (e->isDir)
|
|
|
|
if (e->isDir)
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true);
|
|
|
|
addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true);
|
|
|
|
addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -743,8 +744,8 @@ bool KDirWatchPrivate::useINotify( Entry* e )
|
|
|
|
|
|
|
|
|
|
|
|
bool KDirWatchPrivate::useStat(Entry* e)
|
|
|
|
bool KDirWatchPrivate::useStat(Entry* e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( e->path.startsWith("/media/") || (e->path == "/media")
|
|
|
|
if ( e->path.path().startsWith("/media/") || (e->path.path() == "/media")
|
|
|
|
|| (TDEIO::probably_slow_mounted(e->path)) )
|
|
|
|
|| (TDEIO::probably_slow_mounted(e->path.path())) )
|
|
|
|
useFreq(e, m_nfsPollInterval);
|
|
|
|
useFreq(e, m_nfsPollInterval);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
useFreq(e, m_PollInterval);
|
|
|
|
useFreq(e, m_PollInterval);
|
|
|
@ -761,7 +762,7 @@ bool KDirWatchPrivate::useStat(Entry* e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << " Setup Stat (freq " << e->freq
|
|
|
|
kdDebug(7001) << " Setup Stat (freq " << e->freq
|
|
|
|
<< ") for " << e->path << endl;
|
|
|
|
<< ") for " << e->path.path() << endl;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -772,17 +773,17 @@ bool KDirWatchPrivate::useStat(Entry* e)
|
|
|
|
* Sometimes, entries are dependant on each other: if <sub_entry> !=0,
|
|
|
|
* Sometimes, entries are dependant on each other: if <sub_entry> !=0,
|
|
|
|
* this entry needs another entry to watch himself (when notExistent).
|
|
|
|
* this entry needs another entry to watch himself (when notExistent).
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
|
|
|
|
void KDirWatchPrivate::addEntry(KDirWatch* instance, const KURL& _path,
|
|
|
|
Entry* sub_entry, bool isDir)
|
|
|
|
Entry* sub_entry, bool isDir)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TQString path = _path;
|
|
|
|
TQString path = _path.path();
|
|
|
|
if (path.startsWith("/dev/") || (path == "/dev"))
|
|
|
|
if (path.startsWith("/dev/") || (path == "/dev"))
|
|
|
|
return; // Don't even go there.
|
|
|
|
return; // Don't even go there.
|
|
|
|
|
|
|
|
|
|
|
|
if ( path.length() > 1 && path.right(1) == "/" )
|
|
|
|
if ( path.length() > 1 && path.right(1) == "/" )
|
|
|
|
path.truncate( path.length() - 1 );
|
|
|
|
path.truncate( path.length() - 1 );
|
|
|
|
|
|
|
|
|
|
|
|
EntryMap::Iterator it = m_mapEntries.find( path );
|
|
|
|
EntryMap::Iterator it = m_mapEntries.find( _path );
|
|
|
|
if ( it != m_mapEntries.end() )
|
|
|
|
if ( it != m_mapEntries.end() )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (sub_entry) {
|
|
|
|
if (sub_entry) {
|
|
|
@ -820,7 +821,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
|
|
|
|
mask |= IN_ONLYDIR;
|
|
|
|
mask |= IN_ONLYDIR;
|
|
|
|
|
|
|
|
|
|
|
|
inotify_rm_watch (m_inotify_fd, e->wd);
|
|
|
|
inotify_rm_watch (m_inotify_fd, e->wd);
|
|
|
|
e->wd = inotify_add_watch( m_inotify_fd, TQFile::encodeName( e->path ), mask);
|
|
|
|
e->wd = inotify_add_watch( m_inotify_fd, TQFile::encodeName( e->path.path() ), mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -842,9 +843,9 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
|
|
|
|
bool exists = (KDE_stat(tpath, &stat_buf) == 0);
|
|
|
|
bool exists = (KDE_stat(tpath, &stat_buf) == 0);
|
|
|
|
|
|
|
|
|
|
|
|
Entry newEntry;
|
|
|
|
Entry newEntry;
|
|
|
|
m_mapEntries.insert( path, newEntry );
|
|
|
|
m_mapEntries.insert( _path, newEntry );
|
|
|
|
// the insert does a copy, so we have to use <e> now
|
|
|
|
// the insert does a copy, so we have to use <e> now
|
|
|
|
Entry* e = &(m_mapEntries[path]);
|
|
|
|
Entry* e = &(m_mapEntries[_path]);
|
|
|
|
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
if (exists) {
|
|
|
|
e->isDir = S_ISDIR(stat_buf.st_mode);
|
|
|
|
e->isDir = S_ISDIR(stat_buf.st_mode);
|
|
|
@ -867,7 +868,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
|
|
|
|
e->m_nlink = 0;
|
|
|
|
e->m_nlink = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e->path = path;
|
|
|
|
e->path = _path;
|
|
|
|
if (sub_entry)
|
|
|
|
if (sub_entry)
|
|
|
|
e->m_entries.append(sub_entry);
|
|
|
|
e->m_entries.append(sub_entry);
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -875,7 +876,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << "Added " << (e->isDir ? "Dir ":"File ") << path
|
|
|
|
kdDebug(7001) << "Added " << (e->isDir ? "Dir ":"File ") << path
|
|
|
|
<< (e->m_status == NonExistent ? " NotExisting" : "")
|
|
|
|
<< (e->m_status == NonExistent ? " NotExisting" : "")
|
|
|
|
<< (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path)) : TQString(""))
|
|
|
|
<< (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path.path())) : TQString(""))
|
|
|
|
<< (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString(""))
|
|
|
|
<< (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString(""))
|
|
|
|
<< endl;
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
|
@ -904,7 +905,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
const TQString& _path, Entry* sub_entry )
|
|
|
|
const KURL& _path, Entry* sub_entry )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
kdDebug(7001) << "KDirWatchPrivate::removeEntry for '" << _path << "' sub_entry: " << sub_entry << endl;
|
|
|
|
kdDebug(7001) << "KDirWatchPrivate::removeEntry for '" << _path << "' sub_entry: " << sub_entry << endl;
|
|
|
|
Entry* e = entry(_path);
|
|
|
|
Entry* e = entry(_path);
|
|
|
@ -919,7 +920,7 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
e->removeClient(instance);
|
|
|
|
e->removeClient(instance);
|
|
|
|
|
|
|
|
|
|
|
|
if (e->m_clients.count() || e->m_entries.count()) {
|
|
|
|
if (e->m_clients.count() || e->m_entries.count()) {
|
|
|
|
kdDebug(7001) << "removeEntry: unwatched " << e->path << " " << _path << endl;
|
|
|
|
kdDebug(7001) << "removeEntry: unwatched " << e->path.path() << " " << _path << endl;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -937,13 +938,13 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
FAMCancelMonitor(&fc, &(e->fr) );
|
|
|
|
FAMCancelMonitor(&fc, &(e->fr) );
|
|
|
|
kdDebug(7001) << "Cancelled FAM (Req "
|
|
|
|
kdDebug(7001) << "Cancelled FAM (Req "
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< ") for " << e->path << endl;
|
|
|
|
<< ") for " << e->path.path() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if (e->isDir)
|
|
|
|
if (e->isDir)
|
|
|
|
removeEntry(0, TQDir::cleanDirPath(e->path+"/.."), e);
|
|
|
|
removeEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
removeEntry(0, TQFileInfo(e->path).dirPath(true), e);
|
|
|
|
removeEntry(0, TQFileInfo(e->path.path()).dirPath(true), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -955,13 +956,13 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
(void) inotify_rm_watch( m_inotify_fd, e->wd );
|
|
|
|
(void) inotify_rm_watch( m_inotify_fd, e->wd );
|
|
|
|
kdDebug(7001) << "Cancelled INotify (fd " <<
|
|
|
|
kdDebug(7001) << "Cancelled INotify (fd " <<
|
|
|
|
m_inotify_fd << ", " << e->wd <<
|
|
|
|
m_inotify_fd << ", " << e->wd <<
|
|
|
|
") for " << e->path << endl;
|
|
|
|
") for " << e->path.path() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if (e->isDir)
|
|
|
|
if (e->isDir)
|
|
|
|
removeEntry(0, TQDir::cleanDirPath(e->path+"/.."), e);
|
|
|
|
removeEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
removeEntry(0, TQFileInfo(e->path).dirPath(true), e);
|
|
|
|
removeEntry(0, TQFileInfo(e->path.path()).dirPath(true), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -969,7 +970,7 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
#ifdef HAVE_DNOTIFY
|
|
|
|
#ifdef HAVE_DNOTIFY
|
|
|
|
if (e->m_mode == DNotifyMode) {
|
|
|
|
if (e->m_mode == DNotifyMode) {
|
|
|
|
if (!e->isDir) {
|
|
|
|
if (!e->isDir) {
|
|
|
|
removeEntry(0, TQFileInfo(e->path).dirPath(true), e);
|
|
|
|
removeEntry(0, TQFileInfo(e->path.path()).dirPath(true), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // isDir
|
|
|
|
else { // isDir
|
|
|
|
// must close the FD.
|
|
|
|
// must close the FD.
|
|
|
@ -979,13 +980,13 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
fd_Entry.remove(e->dn_fd);
|
|
|
|
fd_Entry.remove(e->dn_fd);
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << "Cancelled DNotify (fd " << e->dn_fd
|
|
|
|
kdDebug(7001) << "Cancelled DNotify (fd " << e->dn_fd
|
|
|
|
<< ") for " << e->path << endl;
|
|
|
|
<< ") for " << e->path.path() << endl;
|
|
|
|
e->dn_fd = 0;
|
|
|
|
e->dn_fd = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
removeEntry(0, TQDir::cleanDirPath(e->path+"/.."), e);
|
|
|
|
removeEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -999,8 +1000,8 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << "Removed " << (e->isDir ? "Dir ":"File ") << e->path
|
|
|
|
kdDebug(7001) << "Removed " << (e->isDir ? "Dir ":"File ") << e->path.path()
|
|
|
|
<< (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path)) : TQString(""))
|
|
|
|
<< (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path.path())) : TQString(""))
|
|
|
|
<< (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString(""))
|
|
|
|
<< (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString(""))
|
|
|
|
<< endl;
|
|
|
|
<< endl;
|
|
|
|
m_mapEntries.remove( e->path ); // <e> not valid any more
|
|
|
|
m_mapEntries.remove( e->path ); // <e> not valid any more
|
|
|
@ -1052,7 +1053,7 @@ bool KDirWatchPrivate::stopEntryScan( KDirWatch* instance, Entry* e)
|
|
|
|
stillWatching += c->count;
|
|
|
|
stillWatching += c->count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << instance->name() << " stopped scanning " << e->path
|
|
|
|
kdDebug(7001) << instance->name() << " stopped scanning " << e->path.path()
|
|
|
|
<< " (now " << stillWatching << " watchers)" << endl;
|
|
|
|
<< " (now " << stillWatching << " watchers)" << endl;
|
|
|
|
|
|
|
|
|
|
|
|
if (stillWatching == 0) {
|
|
|
|
if (stillWatching == 0) {
|
|
|
@ -1082,7 +1083,7 @@ bool KDirWatchPrivate::restartEntryScan( KDirWatch* instance, Entry* e,
|
|
|
|
if (newWatching == 0)
|
|
|
|
if (newWatching == 0)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
kdDebug(7001) << (instance ? instance->name() : "all") << " restarted scanning " << e->path
|
|
|
|
kdDebug(7001) << (instance ? instance->name() : "all") << " restarted scanning " << e->path.path()
|
|
|
|
<< " (now " << wasWatching+newWatching << " watchers)" << endl;
|
|
|
|
<< " (now " << wasWatching+newWatching << " watchers)" << endl;
|
|
|
|
|
|
|
|
|
|
|
|
// restart watching and emit pending events
|
|
|
|
// restart watching and emit pending events
|
|
|
@ -1091,7 +1092,7 @@ bool KDirWatchPrivate::restartEntryScan( KDirWatch* instance, Entry* e,
|
|
|
|
if (wasWatching == 0) {
|
|
|
|
if (wasWatching == 0) {
|
|
|
|
if (!notify) {
|
|
|
|
if (!notify) {
|
|
|
|
KDE_struct_stat stat_buf;
|
|
|
|
KDE_struct_stat stat_buf;
|
|
|
|
bool exists = (KDE_stat(TQFile::encodeName(e->path), &stat_buf) == 0);
|
|
|
|
bool exists = (KDE_stat(TQFile::encodeName(e->path.path()), &stat_buf) == 0);
|
|
|
|
if (exists) {
|
|
|
|
if (exists) {
|
|
|
|
e->m_ctime = stat_buf.st_ctime;
|
|
|
|
e->m_ctime = stat_buf.st_ctime;
|
|
|
|
e->m_mtime = stat_buf.st_mtime;
|
|
|
|
e->m_mtime = stat_buf.st_mtime;
|
|
|
@ -1170,7 +1171,7 @@ int KDirWatchPrivate::scanEntry(Entry* e)
|
|
|
|
if (e->m_mode == DNotifyMode || e->m_mode == INotifyMode ) {
|
|
|
|
if (e->m_mode == DNotifyMode || e->m_mode == INotifyMode ) {
|
|
|
|
// we know nothing has changed, no need to stat
|
|
|
|
// we know nothing has changed, no need to stat
|
|
|
|
if(!e->dirty) return NoChange;
|
|
|
|
if(!e->dirty) return NoChange;
|
|
|
|
kdDebug(7001) << "scanning " << e->path << " " << e->m_status << " " << e->m_ctime << " " << e->m_mtime << endl;
|
|
|
|
kdDebug(7001) << "scanning " << e->path.path() << " " << e->m_status << " " << e->m_ctime << " " << e->m_mtime << endl;
|
|
|
|
e->dirty = false;
|
|
|
|
e->dirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -1186,7 +1187,7 @@ int KDirWatchPrivate::scanEntry(Entry* e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KDE_struct_stat stat_buf;
|
|
|
|
KDE_struct_stat stat_buf;
|
|
|
|
bool exists = (KDE_stat(TQFile::encodeName(e->path), &stat_buf) == 0);
|
|
|
|
bool exists = (KDE_stat(TQFile::encodeName(e->path.path()), &stat_buf) == 0);
|
|
|
|
if (exists) {
|
|
|
|
if (exists) {
|
|
|
|
|
|
|
|
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
@ -1232,18 +1233,18 @@ int KDirWatchPrivate::scanEntry(Entry* e)
|
|
|
|
* and stored pending events. When watching is stopped, the event is
|
|
|
|
* and stored pending events. When watching is stopped, the event is
|
|
|
|
* added to the pending events.
|
|
|
|
* added to the pending events.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void KDirWatchPrivate::emitEvent(Entry* e, int event, const TQString &fileName)
|
|
|
|
void KDirWatchPrivate::emitEvent(Entry* e, int event, const KURL &fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TQString path = e->path;
|
|
|
|
TQString path = e->path.path();
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
if (!TQDir::isRelativePath(fileName))
|
|
|
|
if (!TQDir::isRelativePath(fileName.path()))
|
|
|
|
path = fileName;
|
|
|
|
path = fileName.path();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
path += "/" + fileName;
|
|
|
|
path += "/" + fileName.path();
|
|
|
|
#elif defined(Q_WS_WIN)
|
|
|
|
#elif defined(Q_WS_WIN)
|
|
|
|
//current drive is passed instead of /
|
|
|
|
//current drive is passed instead of /
|
|
|
|
path += TQDir::currentDirPath().left(2) + "/" + fileName;
|
|
|
|
path += TQDir::currentDirPath().left(2) + "/" + fileName.path();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1279,8 +1280,10 @@ void KDirWatchPrivate::emitEvent(Entry* e, int event, const TQString &fileName)
|
|
|
|
// possible emit Change event after creation
|
|
|
|
// possible emit Change event after creation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (event & Changed)
|
|
|
|
if (event & Changed) {
|
|
|
|
c->instance->setDirty(path);
|
|
|
|
c->instance->setDirty(path);
|
|
|
|
|
|
|
|
c->instance->setDirty(e->path);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1386,11 +1389,11 @@ void KDirWatchPrivate::slotRescan()
|
|
|
|
// Scan parent of deleted directories for new creation
|
|
|
|
// Scan parent of deleted directories for new creation
|
|
|
|
Entry* e;
|
|
|
|
Entry* e;
|
|
|
|
for(e=dList.first();e;e=dList.next())
|
|
|
|
for(e=dList.first();e;e=dList.next())
|
|
|
|
addEntry(0, TQDir::cleanDirPath( e->path+"/.."), e, true);
|
|
|
|
addEntry(0, TQDir::cleanDirPath( e->path.path()+"/.."), e, true);
|
|
|
|
|
|
|
|
|
|
|
|
// Remove watch of parent of new created directories
|
|
|
|
// Remove watch of parent of new created directories
|
|
|
|
for(e=cList.first();e;e=cList.next())
|
|
|
|
for(e=cList.first();e;e=cList.next())
|
|
|
|
removeEntry(0, TQDir::cleanDirPath( e->path+"/.."), e);
|
|
|
|
removeEntry(0, TQDir::cleanDirPath( e->path.path()+"/.."), e);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if ( timerRunning )
|
|
|
|
if ( timerRunning )
|
|
|
@ -1492,7 +1495,7 @@ void KDirWatchPrivate::checkFAMEvent(FAMEvent* fe)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
if (e->m_status == NonExistent) {
|
|
|
|
kdDebug(7001) << "FAM event for nonExistent entry " << e->path << endl;
|
|
|
|
kdDebug(7001) << "FAM event for nonExistent entry " << e->path.path() << endl;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1515,9 +1518,9 @@ void KDirWatchPrivate::checkFAMEvent(FAMEvent* fe)
|
|
|
|
FAMCancelMonitor(&fc, &(e->fr) ); // needed ?
|
|
|
|
FAMCancelMonitor(&fc, &(e->fr) ); // needed ?
|
|
|
|
kdDebug(7001) << "Cancelled FAMReq "
|
|
|
|
kdDebug(7001) << "Cancelled FAMReq "
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< FAMREQUEST_GETREQNUM(&(e->fr))
|
|
|
|
<< " for " << e->path << endl;
|
|
|
|
<< " for " << e->path.path() << endl;
|
|
|
|
// Scan parent for a new creation
|
|
|
|
// Scan parent for a new creation
|
|
|
|
addEntry(0, TQDir::cleanDirPath( e->path+"/.."), e, true);
|
|
|
|
addEntry(0, TQDir::cleanDirPath( e->path.path()+"/.."), e, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -1525,9 +1528,9 @@ void KDirWatchPrivate::checkFAMEvent(FAMEvent* fe)
|
|
|
|
// check for creation of a directory we have to watch
|
|
|
|
// check for creation of a directory we have to watch
|
|
|
|
Entry *sub_entry = e->m_entries.first();
|
|
|
|
Entry *sub_entry = e->m_entries.first();
|
|
|
|
for(;sub_entry; sub_entry = e->m_entries.next())
|
|
|
|
for(;sub_entry; sub_entry = e->m_entries.next())
|
|
|
|
if (sub_entry->path == e->path + "/" + fe->filename) break;
|
|
|
|
if (sub_entry->path.path() == e->path.path() + "/" + fe->filename) break;
|
|
|
|
if (sub_entry && sub_entry->isDir) {
|
|
|
|
if (sub_entry && sub_entry->isDir) {
|
|
|
|
TQString path = e->path;
|
|
|
|
KURL path = e->path;
|
|
|
|
removeEntry(0,e->path,sub_entry); // <e> can be invalid here!!
|
|
|
|
removeEntry(0,e->path,sub_entry); // <e> can be invalid here!!
|
|
|
|
sub_entry->m_status = Normal;
|
|
|
|
sub_entry->m_status = Normal;
|
|
|
|
if (!useFAM(sub_entry))
|
|
|
|
if (!useFAM(sub_entry))
|
|
|
@ -1560,7 +1563,7 @@ void KDirWatchPrivate::statistics()
|
|
|
|
it = m_mapEntries.begin();
|
|
|
|
it = m_mapEntries.begin();
|
|
|
|
for( ; it != m_mapEntries.end(); ++it ) {
|
|
|
|
for( ; it != m_mapEntries.end(); ++it ) {
|
|
|
|
Entry* e = &(*it);
|
|
|
|
Entry* e = &(*it);
|
|
|
|
kdDebug(7001) << " " << e->path << " ("
|
|
|
|
kdDebug(7001) << " " << e->path.path() << " ("
|
|
|
|
<< ((e->m_status==Normal)?"":"Nonexistent ")
|
|
|
|
<< ((e->m_status==Normal)?"":"Nonexistent ")
|
|
|
|
<< (e->isDir ? "Dir":"File") << ", using "
|
|
|
|
<< (e->isDir ? "Dir":"File") << ", using "
|
|
|
|
<< ((e->m_mode == FAMMode) ? "FAM" :
|
|
|
|
<< ((e->m_mode == FAMMode) ? "FAM" :
|
|
|
@ -1648,15 +1651,23 @@ KDirWatch::~KDirWatch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: add watchFiles/recursive support
|
|
|
|
// TODO: add watchFiles/recursive support
|
|
|
|
void KDirWatch::addDir( const TQString& _path,
|
|
|
|
void KDirWatch::addDir( const TQString& _path, bool watchFiles, bool recursive)
|
|
|
|
bool watchFiles, bool recursive)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (watchFiles || recursive) {
|
|
|
|
if (watchFiles || recursive) {
|
|
|
|
kdDebug(7001) << "addDir - recursive/watchFiles not supported yet in KDE 3.x" << endl;
|
|
|
|
kdDebug(7001) << "addDir - recursive/watchFiles not supported yet in TDE 3.x" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (d) d->addEntry(this, _path, 0, true);
|
|
|
|
if (d) d->addEntry(this, _path, 0, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: add watchFiles/recursive support
|
|
|
|
|
|
|
|
void KDirWatch::addDir( const KURL& _url, bool watchFiles, bool recursive)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (watchFiles || recursive) {
|
|
|
|
|
|
|
|
kdDebug(7001) << "addDir - recursive/watchFiles not supported yet in TDE 3.x" << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d) d->addEntry(this, _url, 0, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KDirWatch::addFile( const TQString& _path )
|
|
|
|
void KDirWatch::addFile( const TQString& _path )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (d) d->addEntry(this, _path, 0, false);
|
|
|
|
if (d) d->addEntry(this, _path, 0, false);
|
|
|
@ -1679,6 +1690,11 @@ void KDirWatch::removeDir( const TQString& _path )
|
|
|
|
if (d) d->removeEntry(this, _path, 0);
|
|
|
|
if (d) d->removeEntry(this, _path, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KDirWatch::removeDir( const KURL& _url )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (d) d->removeEntry(this, _url, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KDirWatch::removeFile( const TQString& _path )
|
|
|
|
void KDirWatch::removeFile( const TQString& _path )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (d) d->removeEntry(this, _path, 0);
|
|
|
|
if (d) d->removeEntry(this, _path, 0);
|
|
|
@ -1752,6 +1768,12 @@ void KDirWatch::setDirty( const TQString & _file )
|
|
|
|
emit dirty( _file );
|
|
|
|
emit dirty( _file );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KDirWatch::setDirty( const KURL & _url )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
kdDebug(7001) << name() << " emitting dirty " << _url << endl;
|
|
|
|
|
|
|
|
emit dirty( _url );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KDirWatch::setDeleted( const TQString & _file )
|
|
|
|
void KDirWatch::setDeleted( const TQString & _file )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
kdDebug(7001) << name() << " emitting deleted " << _file << endl;
|
|
|
|
kdDebug(7001) << name() << " emitting deleted " << _file << endl;
|
|
|
|