1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

Make it possible to force generic watchdir implementation in runtime

This commit is contained in:
Mike Gelfand 2016-01-25 21:48:58 +00:00
parent 8eb132aea6
commit 39749f8e4b
6 changed files with 58 additions and 24 deletions

View file

@ -559,17 +559,14 @@ daemon_start (void * raw_arg,
daemon_reconfigure (arg);
/* maybe add a watchdir */
if (tr_variantDictFindBool (settings, TR_KEY_watch_dir_enabled, &boolVal) && boolVal)
{
const char * dir;
if (tr_variantDictFindBool (settings, TR_KEY_watch_dir_enabled, &boolVal)
&& boolVal
&& tr_variantDictFindStr (settings, TR_KEY_watch_dir, &dir, NULL)
&& dir
&& *dir)
if (tr_variantDictFindStr (settings, TR_KEY_watch_dir, &dir, NULL) && dir != NULL && *dir != '\0')
{
tr_logAddInfo ("Watching \"%s\" for new .torrent files", dir);
if ((watchdir = tr_watchdir_new (dir, &onFileAdded, mySession, ev_base)) == NULL)
if ((watchdir = tr_watchdir_new (dir, &onFileAdded, mySession, ev_base, false)) == NULL)
goto cleanup;
}
}

View file

@ -259,11 +259,22 @@ if(ENABLE_TESTS)
set(crypto-test_ADD_SOURCES crypto-test-ref.h)
set(watchdir@generic-test_DEFINITIONS WATCHDIR_TEST_FORCE_GENERIC)
foreach(T bitfield blocklist clients crypto error file history json magnet metainfo move peer-msgs quark rename rpc session
tr-getopt utils variant watchdir)
tr-getopt utils variant watchdir watchdir@generic)
set(TP ${TR_NAME}-test-${T})
add_executable(${TP} ${T}-test.c ${${T}-test_ADD_SOURCES})
if(T MATCHES "^([^@]+)@.+$")
string(REPLACE "@" "_" TP "${TP}")
set(${TP}_TEST_BASENAME "${CMAKE_MATCH_1}")
else()
set(${TP}_TEST_BASENAME "${T}")
endif()
add_executable(${TP} ${${TP}_TEST_BASENAME}-test.c ${${T}-test_ADD_SOURCES})
target_link_libraries(${TP} ${TR_NAME} ${TR_NAME}-test)
if(DEFINED ${T}-test_DEFINITIONS)
target_compile_definitions(${TP} PRIVATE ${${T}-test_DEFINITIONS})
endif()
add_test(NAME ${T} COMMAND ${TP})
set_property(TARGET ${TP} PROPERTY FOLDER "UnitTests")
endforeach()

View file

@ -188,7 +188,8 @@ TESTS = \
tr-getopt-test \
utils-test \
variant-test \
watchdir-test
watchdir-test \
watchdir-generic-test
noinst_PROGRAMS = $(TESTS)
@ -289,6 +290,11 @@ watchdir_test_SOURCES = watchdir-test.c $(TEST_SOURCES)
watchdir_test_LDADD = ${apps_ldadd}
watchdir_test_LDFLAGS = ${apps_ldflags}
watchdir_generic_test_SOURCES = watchdir-test.c $(TEST_SOURCES)
watchdir_generic_test_LDADD = ${apps_ldadd}
watchdir_generic_test_LDFLAGS = ${apps_ldflags}
watchdir_generic_test_CPPFLAGS = -DWATCHDIR_TEST_FORCE_GENERIC $(AM_CPPFLAGS)
rename_test_SOURCES = rename-test.c $(TEST_SOURCES)
rename_test_LDADD = ${apps_ldadd}
rename_test_LDFLAGS = ${apps_ldflags}

View file

@ -97,6 +97,21 @@ create_dir (const char * parent_dir,
tr_free (path);
}
tr_watchdir_t
create_watchdir (const char * path,
tr_watchdir_cb callback,
void * callback_user_data,
struct event_base * event_base)
{
#ifdef WATCHDIR_TEST_FORCE_GENERIC
const bool force_generic = true;
#else
const bool force_generic = false;
#endif
return tr_watchdir_new (path, callback, callback_user_data, event_base, force_generic);
}
/***
****
***/
@ -109,7 +124,7 @@ test_construct (void)
ev_base = event_base_new();
wd = tr_watchdir_new (test_dir, &callback, NULL, ev_base);
wd = create_watchdir (test_dir, &callback, NULL, ev_base);
check (wd != NULL);
check (tr_sys_path_is_same (test_dir, tr_watchdir_get_path (wd), NULL));
@ -136,7 +151,7 @@ test_initial_scan (void)
callback_data wd_data = CB_DATA_STATIC_INIT;
reset_callback_data (&wd_data, TR_WATCHDIR_ACCEPT);
tr_watchdir_t wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
tr_watchdir_t wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
check (wd != NULL);
process_events ();
@ -153,7 +168,7 @@ test_initial_scan (void)
callback_data wd_data = CB_DATA_STATIC_INIT;
reset_callback_data (&wd_data, TR_WATCHDIR_ACCEPT);
tr_watchdir_t wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
tr_watchdir_t wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
check (wd != NULL);
process_events ();
@ -184,7 +199,7 @@ test_watch (void)
tr_watchdir_generic_interval = ONE_HUNDRED_MSEC;
reset_callback_data (&wd_data, TR_WATCHDIR_ACCEPT);
wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
check (wd != NULL);
process_events ();
@ -239,11 +254,11 @@ test_watch_two_dirs (void)
create_dir (dir2, NULL);
reset_callback_data (&wd1_data, TR_WATCHDIR_ACCEPT);
wd1 = tr_watchdir_new (dir1, &callback, &wd1_data, ev_base);
wd1 = create_watchdir (dir1, &callback, &wd1_data, ev_base);
check (wd1 != NULL);
reset_callback_data (&wd2_data, TR_WATCHDIR_ACCEPT);
wd2 = tr_watchdir_new (dir2, &callback, &wd2_data, ev_base);
wd2 = create_watchdir (dir2, &callback, &wd2_data, ev_base);
check (wd2 != NULL);
process_events ();
@ -347,7 +362,7 @@ test_retry (void)
tr_watchdir_retry_max_interval = tr_watchdir_retry_start_interval;
reset_callback_data (&wd_data, TR_WATCHDIR_RETRY);
wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
check (wd != NULL);
process_events ();

View file

@ -232,7 +232,8 @@ tr_watchdir_t
tr_watchdir_new (const char * path,
tr_watchdir_cb callback,
void * callback_user_data,
struct event_base * event_base)
struct event_base * event_base,
bool force_generic)
{
tr_watchdir_t handle;
@ -243,18 +244,21 @@ tr_watchdir_new (const char * path,
handle->event_base = event_base;
tr_watchdir_retries_init (&handle->active_retries);
if (!force_generic)
{
#ifdef WITH_INOTIFY
if (handle->backend == NULL)
handle->backend = tr_watchdir_inotify_new (handle);
if (handle->backend == NULL)
handle->backend = tr_watchdir_inotify_new (handle);
#endif
#ifdef WITH_KQUEUE
if (handle->backend == NULL)
handle->backend = tr_watchdir_kqueue_new (handle);
if (handle->backend == NULL)
handle->backend = tr_watchdir_kqueue_new (handle);
#endif
#ifdef _WIN32
if (handle->backend == NULL)
handle->backend = tr_watchdir_win32_new (handle);
if (handle->backend == NULL)
handle->backend = tr_watchdir_win32_new (handle);
#endif
}
if (handle->backend == NULL)
handle->backend = tr_watchdir_generic_new (handle);

View file

@ -35,7 +35,8 @@ typedef tr_watchdir_status (* tr_watchdir_cb) (tr_watchdir_t handle,
tr_watchdir_t tr_watchdir_new (const char * path,
tr_watchdir_cb callback,
void * callback_user_data,
struct event_base * event_base);
struct event_base * event_base,
bool force_generic);
void tr_watchdir_free (tr_watchdir_t handle);