handle directory creation
This commit is contained in:
parent
07d4d26e61
commit
c78a055bb2
@ -2,7 +2,7 @@
|
|||||||
#define _RCLMON_H_INCLUDED_
|
#define _RCLMON_H_INCLUDED_
|
||||||
#include "autoconfig.h"
|
#include "autoconfig.h"
|
||||||
#ifdef RCL_MONITOR
|
#ifdef RCL_MONITOR
|
||||||
/* @(#$Id: rclmon.h,v 1.2 2006-10-17 14:41:59 dockes Exp $ (C) 2006 J.F.Dockes */
|
/* @(#$Id: rclmon.h,v 1.3 2006-10-23 15:01:12 dockes Exp $ (C) 2006 J.F.Dockes */
|
||||||
/**
|
/**
|
||||||
* Definitions for the real-time monitoring recoll.
|
* Definitions for the real-time monitoring recoll.
|
||||||
* We're interested in file modifications, deletions and renaming.
|
* We're interested in file modifications, deletions and renaming.
|
||||||
@ -26,7 +26,8 @@ using std::multimap;
|
|||||||
|
|
||||||
class RclMonEvent {
|
class RclMonEvent {
|
||||||
public:
|
public:
|
||||||
enum EvType {RCLEVT_NONE, RCLEVT_MODIFY, RCLEVT_DELETE, RCLEVT_RENAME};
|
enum EvType {RCLEVT_NONE, RCLEVT_MODIFY, RCLEVT_DELETE,
|
||||||
|
RCLEVT_DIRCREATE, RCLEVT_RENAME};
|
||||||
string m_path;
|
string m_path;
|
||||||
string m_opath;
|
string m_opath;
|
||||||
EvType m_etyp;
|
EvType m_etyp;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "autoconfig.h"
|
#include "autoconfig.h"
|
||||||
#ifdef RCL_MONITOR
|
#ifdef RCL_MONITOR
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rclmonrcv.cpp,v 1.4 2006-10-23 14:29:49 dockes Exp $ (C) 2006 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rclmonrcv.cpp,v 1.5 2006-10-23 15:01:12 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -40,7 +40,7 @@ class RclMonitor {
|
|||||||
public:
|
public:
|
||||||
RclMonitor(){}
|
RclMonitor(){}
|
||||||
virtual ~RclMonitor() {}
|
virtual ~RclMonitor() {}
|
||||||
virtual bool addWatch(const string& path, const struct stat&) = 0;
|
virtual bool addWatch(const string& path, bool isDir) = 0;
|
||||||
virtual bool getEvent(RclMonEvent& ev, int secs = -1) = 0;
|
virtual bool getEvent(RclMonEvent& ev, int secs = -1) = 0;
|
||||||
virtual bool ok() = 0;
|
virtual bool ok() = 0;
|
||||||
// Does this monitor generate 'exist' events at startup?
|
// Does this monitor generate 'exist' events at startup?
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_mon || !m_mon->ok() || !m_mon->addWatch(fn, *st))
|
if (!m_mon || !m_mon->ok() || !m_mon->addWatch(fn, true))
|
||||||
return FsTreeWalker::FtwError;
|
return FsTreeWalker::FtwError;
|
||||||
} else if (!m_mon->generatesExist() &&
|
} else if (!m_mon->generatesExist() &&
|
||||||
flg == FsTreeWalker::FtwRegular) {
|
flg == FsTreeWalker::FtwRegular) {
|
||||||
@ -156,6 +156,9 @@ void *rclMonRcvRun(void *q)
|
|||||||
-1
|
-1
|
||||||
#endif
|
#endif
|
||||||
)) {
|
)) {
|
||||||
|
if (ev.m_etyp == RclMonEvent::RCLEVT_DIRCREATE) {
|
||||||
|
mon->addWatch(ev.m_path, true);
|
||||||
|
}
|
||||||
queue->pushEvent(ev);
|
queue->pushEvent(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +181,7 @@ class RclFAM : public RclMonitor {
|
|||||||
public:
|
public:
|
||||||
RclFAM();
|
RclFAM();
|
||||||
virtual ~RclFAM();
|
virtual ~RclFAM();
|
||||||
virtual bool addWatch(const string& path, const struct stat& st);
|
virtual bool addWatch(const string& path, bool isdir);
|
||||||
virtual bool getEvent(RclMonEvent& ev, int secs = -1);
|
virtual bool getEvent(RclMonEvent& ev, int secs = -1);
|
||||||
bool ok() {return m_ok;}
|
bool ok() {return m_ok;}
|
||||||
virtual bool generatesExist() {return true;}
|
virtual bool generatesExist() {return true;}
|
||||||
@ -234,18 +237,18 @@ RclFAM::~RclFAM()
|
|||||||
FAMClose(&m_conn);
|
FAMClose(&m_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RclFAM::addWatch(const string& path, const struct stat& st)
|
bool RclFAM::addWatch(const string& path, bool isdir)
|
||||||
{
|
{
|
||||||
if (!ok())
|
if (!ok())
|
||||||
return false;
|
return false;
|
||||||
LOGDEB(("RclFAM::addWatch: adding %s\n", path.c_str()));
|
LOGDEB(("RclFAM::addWatch: adding %s\n", path.c_str()));
|
||||||
FAMRequest req;
|
FAMRequest req;
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (isdir) {
|
||||||
if (FAMMonitorDirectory(&m_conn, path.c_str(), &req, 0) != 0) {
|
if (FAMMonitorDirectory(&m_conn, path.c_str(), &req, 0) != 0) {
|
||||||
LOGERR(("RclFAM::addWatch: FAMMonitorDirectory failed\n"));
|
LOGERR(("RclFAM::addWatch: FAMMonitorDirectory failed\n"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (S_ISREG(st.st_mode)) {
|
} else {
|
||||||
if (FAMMonitorFile(&m_conn, path.c_str(), &req, 0) != 0) {
|
if (FAMMonitorFile(&m_conn, path.c_str(), &req, 0) != 0) {
|
||||||
LOGERR(("RclFAM::addWatch: FAMMonitorFile failed\n"));
|
LOGERR(("RclFAM::addWatch: FAMMonitorFile failed\n"));
|
||||||
return false;
|
return false;
|
||||||
@ -303,8 +306,13 @@ bool RclFAM::getEvent(RclMonEvent& ev, int secs)
|
|||||||
event_name(fe.code), ev.m_path.c_str()));
|
event_name(fe.code), ev.m_path.c_str()));
|
||||||
|
|
||||||
switch (fe.code) {
|
switch (fe.code) {
|
||||||
case FAMChanged:
|
|
||||||
case FAMCreated:
|
case FAMCreated:
|
||||||
|
if (path_isdir(ev.m_path)) {
|
||||||
|
ev.m_etyp = RclMonEvent::RCLEVT_DIRCREATE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case FAMChanged:
|
||||||
case FAMExists:
|
case FAMExists:
|
||||||
// Let the other side sort out the status of this file vs the db
|
// Let the other side sort out the status of this file vs the db
|
||||||
ev.m_etyp = RclMonEvent::RCLEVT_MODIFY;
|
ev.m_etyp = RclMonEvent::RCLEVT_MODIFY;
|
||||||
@ -341,7 +349,7 @@ class RclIntf : public RclMonitor {
|
|||||||
public:
|
public:
|
||||||
RclIntf();
|
RclIntf();
|
||||||
virtual ~RclIntf();
|
virtual ~RclIntf();
|
||||||
virtual bool addWatch(const string& path, const struct stat& st);
|
virtual bool addWatch(const string& path, bool isdir);
|
||||||
virtual bool getEvent(RclMonEvent& ev, int secs = -1);
|
virtual bool getEvent(RclMonEvent& ev, int secs = -1);
|
||||||
bool ok() {return m_ok;}
|
bool ok() {return m_ok;}
|
||||||
virtual bool generatesExist() {return false;}
|
virtual bool generatesExist() {return false;}
|
||||||
@ -408,13 +416,13 @@ RclIntf::~RclIntf()
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RclIntf::addWatch(const string& path, const struct stat& st)
|
bool RclIntf::addWatch(const string& path, bool)
|
||||||
{
|
{
|
||||||
if (!ok())
|
if (!ok())
|
||||||
return false;
|
return false;
|
||||||
LOGDEB(("RclIntf::addWatch: adding %s\n", path.c_str()));
|
LOGDEB(("RclIntf::addWatch: adding %s\n", path.c_str()));
|
||||||
// CLOSE_WRITE and CREATE are covered through MODIFY
|
// CLOSE_WRITE is covered through MODIFY. CREATE is needed for mkdirs
|
||||||
uint32_t mask = IN_MODIFY
|
uint32_t mask = IN_MODIFY | IN_CREATE
|
||||||
| IN_MOVED_FROM | IN_MOVED_TO
|
| IN_MOVED_FROM | IN_MOVED_TO
|
||||||
| IN_DELETE
|
| IN_DELETE
|
||||||
#ifdef IN_DONT_FOLLOW
|
#ifdef IN_DONT_FOLLOW
|
||||||
@ -496,6 +504,13 @@ bool RclIntf::getEvent(RclMonEvent& ev, int secs)
|
|||||||
ev.m_etyp = RclMonEvent::RCLEVT_MODIFY;
|
ev.m_etyp = RclMonEvent::RCLEVT_MODIFY;
|
||||||
} else if (evp->mask & (IN_DELETE | IN_MOVED_FROM)) {
|
} else if (evp->mask & (IN_DELETE | IN_MOVED_FROM)) {
|
||||||
ev.m_etyp = RclMonEvent::RCLEVT_DELETE;
|
ev.m_etyp = RclMonEvent::RCLEVT_DELETE;
|
||||||
|
} else if (evp->mask & (IN_CREATE)) {
|
||||||
|
if (path_isdir(ev.m_path)) {
|
||||||
|
ev.m_etyp = RclMonEvent::RCLEVT_DIRCREATE;
|
||||||
|
} else {
|
||||||
|
// Will get modify event
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGDEB(("RclIntf::getEvent: unhandled event %s 0x%x %s\n",
|
LOGDEB(("RclIntf::getEvent: unhandled event %s 0x%x %s\n",
|
||||||
event_name(evp->mask), evp->mask, ev.m_path.c_str()));
|
event_name(evp->mask), evp->mask, ev.m_path.c_str()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user