".DS_Store",\r
NULL\r
};\r
+static struct fce_close_event last_close_event;\r
\r
/*\r
*\r
* */\r
static void send_fce_event( char *path, int mode )\r
{ \r
+ static int first_event = FCE_TRUE;\r
+\r
struct fce_packet packet;\r
void *data = &packet;\r
static uint32_t event_id = 0; /* the unique packet couter to detect packet/data loss. Going from 0xFFFFFFFF to 0x0 is a valid increment */\r
+ time_t now = time(NULL);\r
\r
LOG(log_debug, logtype_afpd, "send_fce_event: start");\r
\r
- time_t now = time(NULL);\r
+ /* initialized ? */\r
+ if (first_event == FCE_TRUE) {\r
+ first_event = FCE_FALSE;\r
+ fce_init_udp();\r
+ /* Notify listeners the we start from the beginning */\r
+ send_fce_event( "", FCE_CONN_START );\r
+ }\r
\r
/* build our data packet */\r
ssize_t data_len = build_fce_packet( &packet, path, mode, ++event_id );\r
return AFP_OK;\r
}\r
\r
+static void save_close_event(const char *path)\r
+{\r
+ time_t now = time(NULL);\r
+\r
+ /* Check if it's a close for the same event as the last one */\r
+ if (last_close_event.time /* is there any saved event ? */\r
+ && (strcmp(path, last_close_event.path) != 0)) {\r
+ /* no, so send the saved event out now */\r
+ send_fce_event(last_close_event.path, FCE_FILE_MODIFY);\r
+ }\r
+\r
+ LOG(log_debug, logtype_afpd, "save_close_event: %s", path);\r
+\r
+ last_close_event.time = now;\r
+ strncpy(last_close_event.path, path, MAXPATHLEN);\r
+}\r
+\r
/*\r
*\r
* Dispatcher for all incoming file change events\r
* */\r
static int register_fce(const char *u_name, int is_dir, int mode)\r
{\r
+ static int first_event = FCE_TRUE;\r
+\r
if (udp_sockets == 0)\r
/* No listeners configured */\r
return AFP_OK;\r
if (u_name == NULL)\r
return AFPERR_PARAM;\r
\r
- static int first_event = FCE_TRUE;\r
-\r
/* do some initialization on the fly the first time */\r
if (first_event) {\r
fce_initialize_history();\r
+ first_event = FCE_FALSE;\r
}\r
\r
/* handle files which should not cause events (.DS_Store atc. ) */\r
\r
LOG(log_debug9, logtype_afpd, "Detected fc event <%d> for <%s>", mode, full_path_buffer );\r
\r
-\r
- /* we do initilization on the fly, no blocking calls in here \r
- * (except when using FQDN in broken DNS environment)\r
- */\r
- if (first_event == FCE_TRUE)\r
- {\r
- fce_init_udp();\r
- \r
- /* Notify listeners the we start from the beginning */\r
- send_fce_event( "", FCE_CONN_START );\r
- \r
- first_event = FCE_FALSE;\r
+ if (mode & FCE_FILE_MODIFY) {\r
+ save_close_event(full_path_buffer);\r
+ return AFP_OK;\r
}\r
\r
- /* Handle UDP transport */\r
send_fce_event( full_path_buffer, mode );\r
\r
return AFP_OK;\r
}\r
\r
+static void check_saved_close_events(int fmodwait)\r
+{\r
+ time_t now = time(NULL);\r
+\r
+ /* check if configured holdclose time has passed */\r
+ if (last_close_event.time && ((last_close_event.time + fmodwait) < now)) {\r
+ LOG(log_debug, logtype_afpd, "check_saved_close_events: sending event: %s", last_close_event.path);\r
+ /* yes, send event */\r
+ send_fce_event(&last_close_event.path[0], FCE_FILE_MODIFY);\r
+ last_close_event.path[0] = 0;\r
+ last_close_event.time = 0;\r
+ }\r
+}\r
\r
/******************** External calls start here **************************/\r
\r
* */\r
#ifndef FCE_TEST_MAIN\r
\r
+void fce_pending_events(AFPObj *obj)\r
+{\r
+ vol_fce_tm_event();\r
+ check_saved_close_events(obj->options.fce_fmodwait);\r
+}\r
+\r
int fce_register_delete_file( struct path *path )\r
{\r
int ret = AFP_OK;\r