Switch to unified view

a/src/index/rclmonrcv.cpp b/src/index/rclmonrcv.cpp
...
...
31
/**
31
/**
32
 * Recoll real time monitor event receiver. This file has code to interface 
32
 * Recoll real time monitor event receiver. This file has code to interface 
33
 * to FAM or inotify and place events on the event queue.
33
 * to FAM or inotify and place events on the event queue.
34
 */
34
 */
35
35
36
/** A small virtual interface for monitors. Probably suitable to let
36
/** A small virtual interface for monitors. Lets
37
    either of fam/gamin or raw imonitor hide behind */
37
 *  either fam/gamin or raw imonitor hide behind 
38
 */
38
class RclMonitor {
39
class RclMonitor {
39
public:
40
public:
40
    RclMonitor(){}
41
    RclMonitor()
42
  : saved_errno(0)
43
    {
44
    }
45
41
    virtual ~RclMonitor() {}
46
    virtual ~RclMonitor() 
47
    {
48
    }
42
    virtual bool addWatch(const string& path, bool isDir) = 0;
49
    virtual bool addWatch(const string& path, bool isDir) = 0;
43
    virtual bool getEvent(RclMonEvent& ev, int msecs = -1) = 0;
50
    virtual bool getEvent(RclMonEvent& ev, int msecs = -1) = 0;
44
    virtual bool ok() const = 0;
51
    virtual bool ok() const = 0;
45
    // Does this monitor generate 'exist' events at startup?
52
    // Does this monitor generate 'exist' events at startup?
46
    virtual bool generatesExist() const = 0; 
53
    virtual bool generatesExist() const = 0; 
54
55
    // Save significant errno after monitor calls
56
    int saved_errno;
47
};
57
};
48
58
49
// Monitor factory. We only have one compiled-in kind at a time, no
59
// Monitor factory. We only have one compiled-in kind at a time, no
50
// need for a 'kind' parameter
60
// need for a 'kind' parameter
51
static RclMonitor *makeMonitor();
61
static RclMonitor *makeMonitor();
...
...
92
        } else {
102
        } else {
93
            MONDEB(("rclMonRcvRun: no event pending\n"));
103
            MONDEB(("rclMonRcvRun: no event pending\n"));
94
            break;
104
            break;
95
        }
105
        }
96
        }
106
        }
97
      if (!m_mon || !m_mon->ok() || !m_mon->addWatch(fn, true))
107
      if (!m_mon || !m_mon->ok())
98
        return FsTreeWalker::FtwError;
108
        return FsTreeWalker::FtwError;
109
      // We do nothing special if addWatch fails for a reasonable reason
110
      if (!m_mon->addWatch(fn, true)) {
111
      if (m_mon->saved_errno != EACCES && 
112
          m_mon->saved_errno != ENOENT)
113
          return FsTreeWalker::FtwError;
114
      }
99
    } else if (!m_mon->generatesExist() && 
115
    } else if (!m_mon->generatesExist() && 
100
           flg == FsTreeWalker::FtwRegular) {
116
           flg == FsTreeWalker::FtwRegular) {
101
        // Have to synthetize events for regular files existence
117
        // Have to synthetize events for regular files existence
102
        // at startup because the monitor does not do it
118
        // at startup because the monitor does not do it
103
        // Note 2011-09-29: no sure this is actually needed. We just ran
119
        // Note 2011-09-29: no sure this is actually needed. We just ran
...
...
196
        string beaglequeuedir;
212
        string beaglequeuedir;
197
        if (!lconfig.getConfParam("beaglequeuedir", beaglequeuedir))
213
        if (!lconfig.getConfParam("beaglequeuedir", beaglequeuedir))
198
        beaglequeuedir = path_tildexpand("~/.beagle/ToIndex/");
214
        beaglequeuedir = path_tildexpand("~/.beagle/ToIndex/");
199
        if (!mon->addWatch(beaglequeuedir, true)) {
215
        if (!mon->addWatch(beaglequeuedir, true)) {
200
        LOGERR(("rclMonRcvRun: addwatch (beaglequeuedit) failed\n"));
216
        LOGERR(("rclMonRcvRun: addwatch (beaglequeuedit) failed\n"));
217
      if (mon->saved_errno != EACCES && mon->saved_errno != ENOENT)
201
        goto terminate;
218
            goto terminate;
202
        }
219
        }
203
    }
220
    }
204
    }
221
    }
205
222
206
    // Forever wait for monitoring events and add them to queue:
223
    // Forever wait for monitoring events and add them to queue:
...
...
591
    | IN_EXCL_UNLINK
608
    | IN_EXCL_UNLINK
592
#endif
609
#endif
593
    ;
610
    ;
594
    int wd;
611
    int wd;
595
    if ((wd = inotify_add_watch(m_fd, path.c_str(), mask)) < 0) {
612
    if ((wd = inotify_add_watch(m_fd, path.c_str(), mask)) < 0) {
613
  saved_errno = errno;
596
        LOGERR(("RclIntf::addWatch: inotify_add_watch failed\n"));
614
        LOGERR(("RclIntf::addWatch: inotify_add_watch failed. errno %d\n",
615
         saved_errno));
597
    return false;
616
    return false;
598
    }
617
    }
599
    m_idtopath[wd] = path;
618
    m_idtopath[wd] = path;
600
    return true;
619
    return true;
601
}
620
}