forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_libfilewatcher.c
81 lines (76 loc) · 2.31 KB
/
test_libfilewatcher.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/******************************************************************************
* Copyright (C) 2014-2018 Zhifeng Gong <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with libraries; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "libfilewatcher.h"
#define ROOT_DIR "./"
static struct fw *_fw = NULL;
void ctrl_c_op(int signo)
{
fw_deinit(_fw);
printf("file_watcher exit\n");
}
void on_change(struct fw *fw, enum fw_type type, char *path)
{
switch (type) {
case FW_CREATE_DIR:
printf("[CREATE DIR] %s\n", path);
break;
case FW_CREATE_FILE:
printf("[CREATE FILE] %s\n", path);
break;
case FW_DELETE_DIR:
printf("[DELETE DIR] %s\n", path);
break;
case FW_DELETE_FILE:
printf("[DELETE FILE] %s\n", path);
break;
case FW_MOVE_FROM_DIR:
printf("[MOVE FROM DIR] %s\n", path);
break;
case FW_MOVE_TO_DIR:
printf("[MOVE TO DIR] %s\n", path);
break;
case FW_MOVE_FROM_FILE:
printf("[MOVE FROM FILE] %s\n", path);
break;
case FW_MOVE_TO_FILE:
printf("[MOVE TO FILE] %s\n", path);
break;
case FW_MODIFY_FILE:
printf("[MODIFY FILE] %s\n", path);
break;
default:
break;
}
}
int main(int argc, char **argv)
{
signal(SIGINT, ctrl_c_op);
_fw = fw_init(on_change);
if (!_fw) {
printf("fw_init failed!\n");
return -1;
}
fw_add_watch_recursive(_fw, ROOT_DIR);
fw_dispatch(_fw);
return 0;
}