diff --git a/daemon/daemon.c b/daemon/daemon.c index cefd7ab62..26f1c1d2d 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -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; } } diff --git a/libtransmission/CMakeLists.txt b/libtransmission/CMakeLists.txt index 83e8abfd0..bc3911efb 100644 --- a/libtransmission/CMakeLists.txt +++ b/libtransmission/CMakeLists.txt @@ -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() diff --git a/libtransmission/Makefile.am b/libtransmission/Makefile.am index b39b1ef34..f91769a95 100644 --- a/libtransmission/Makefile.am +++ b/libtransmission/Makefile.am @@ -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} diff --git a/libtransmission/watchdir-test.c b/libtransmission/watchdir-test.c index d77b7bf73..8ed8b30bc 100644 --- a/libtransmission/watchdir-test.c +++ b/libtransmission/watchdir-test.c @@ -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 (); diff --git a/libtransmission/watchdir.c b/libtransmission/watchdir.c index b51368892..a774a7a64 100644 --- a/libtransmission/watchdir.c +++ b/libtransmission/watchdir.c @@ -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); diff --git a/libtransmission/watchdir.h b/libtransmission/watchdir.h index 766abf3ef..ff818beb2 100644 --- a/libtransmission/watchdir.h +++ b/libtransmission/watchdir.h @@ -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);