Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: don't emit fs-event callback after uv_fs_event handle is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Nov 3, 2011
1 parent 77a2477 commit 0fb3769
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/win/fs-event.c
Expand Up @@ -353,7 +353,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
offset = file_info->NextEntryOffset;
} while(offset);
} else {
handle->cb(handle, NULL, UV_CHANGE, 0);
if (!(handle->flags & UV_HANDLE_CLOSING)) {
handle->cb(handle, NULL, UV_CHANGE, 0);
}
}
} else {
uv__set_sys_error(loop, GET_REQ_ERROR(req));
Expand Down
29 changes: 29 additions & 0 deletions test/test-fs-event.c
Expand Up @@ -235,3 +235,32 @@ TEST_IMPL(fs_event_watch_file_current_dir) {
r = uv_fs_unlink(loop, &fs_req, "watch_file", NULL);
return 0;
}


TEST_IMPL(fs_event_no_callback_on_close) {
uv_fs_t fs_req;
uv_loop_t* loop = uv_default_loop();
int r;

/* Setup */
uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);
create_dir(loop, "watch_dir");
create_file(loop, "watch_dir/file1");

r = uv_fs_event_init(loop, &fs_event, "watch_dir/file1", fs_event_cb_file);
ASSERT(r != -1);

uv_close((uv_handle_t*)&fs_event, close_cb);

uv_run(loop);

ASSERT(fs_event_cb_called == 0);
ASSERT(close_cb_called == 1);

/* Cleanup */
r = uv_fs_unlink(loop, &fs_req, "watch_dir/file1", NULL);
r = uv_fs_rmdir(loop, &fs_req, "watch_dir", NULL);

return 0;
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -106,6 +106,7 @@ TEST_DECLARE (fs_stat_missing_path)
TEST_DECLARE (fs_event_watch_dir)
TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (fs_open_dir)
Expand Down Expand Up @@ -252,6 +253,7 @@ TASK_LIST_START
TEST_ENTRY (fs_event_watch_dir)
TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_event_no_callback_on_close)
TEST_ENTRY (fs_readdir_empty_dir)
TEST_ENTRY (fs_readdir_file)
TEST_ENTRY (fs_open_dir)
Expand Down

0 comments on commit 0fb3769

Please sign in to comment.