forked from Xyaneon/grive-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.h
61 lines (52 loc) · 2.21 KB
/
watch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
grive-daemon syncs your ~/Google Drive folder by calling grive.
Copyright (C) 2014 Christopher Kyle Horton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WATCH_H
#define WATCH_H
#include <iostream>
#include <string>
#include <sys/inotify.h>
#include <map>
#include <dirent.h>
#define WATCH_FLAGS (IN_ATTRIB | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO)
using std::string;
using std::map;
using std::cout;
using std::endl;
class Watch {
struct wd_elem {
int pd;
string name;
bool operator() (const wd_elem &l, const wd_elem &r) const
{ return l.pd < r.pd ? true : l.pd == r.pd && l.name < r.name ? true : false; }
};
map<int, wd_elem> watch;
map<wd_elem, int, wd_elem> rwatch;
public:
// Insert event information, used to create new watch, into Watch object.
void insert( int pd, const string &name, int wd );
// Erase watch specified by pd (parent watch descriptor) and name from watch list.
// Returns full name (for display etc), and wd, which is required for inotify_rm_watch.
string erase( int pd, const string &name, int *wd );
// Given a watch descriptor, return the full directory name as string. Recurses up parent WDs to assemble name,
// an idea borrowed from Windows change journals.
string get( int wd );
// Given a parent wd and name (provided in IN_DELETE events), return the watch descriptor.
// Main purpose is to help remove directories from watch list.
int get( int pd, string name );
void cleanup( int fd );
void stats();
};
#endif