Changeset 14674


Ignore:
Timestamp:
Jan 25, 2016, 9:48:58 PM (5 years ago)
Author:
mikedld
Message:

Make it possible to force generic watchdir implementation in runtime

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r14651 r14674  
    560560
    561561    /* maybe add a watchdir */
     562    if (tr_variantDictFindBool (settings, TR_KEY_watch_dir_enabled, &boolVal) && boolVal)
    562563    {
    563564        const char * dir;
    564565
    565         if (tr_variantDictFindBool (settings, TR_KEY_watch_dir_enabled, &boolVal)
    566             && boolVal
    567             && tr_variantDictFindStr (settings, TR_KEY_watch_dir, &dir, NULL)
    568             && dir
    569             && *dir)
     566        if (tr_variantDictFindStr (settings, TR_KEY_watch_dir, &dir, NULL) && dir != NULL && *dir != '\0')
    570567        {
    571568            tr_logAddInfo ("Watching \"%s\" for new .torrent files", dir);
    572             if ((watchdir = tr_watchdir_new (dir, &onFileAdded, mySession, ev_base)) == NULL)
     569            if ((watchdir = tr_watchdir_new (dir, &onFileAdded, mySession, ev_base, false)) == NULL)
    573570                goto cleanup;
    574571        }
  • trunk/libtransmission/CMakeLists.txt

    r14661 r14674  
    260260    set(crypto-test_ADD_SOURCES crypto-test-ref.h)
    261261
     262    set(watchdir@generic-test_DEFINITIONS WATCHDIR_TEST_FORCE_GENERIC)
     263
    262264    foreach(T bitfield blocklist clients crypto error file history json magnet metainfo move peer-msgs quark rename rpc session
    263               tr-getopt utils variant watchdir)
     265              tr-getopt utils variant watchdir watchdir@generic)
    264266        set(TP ${TR_NAME}-test-${T})
    265         add_executable(${TP} ${T}-test.c ${${T}-test_ADD_SOURCES})
     267        if(T MATCHES "^([^@]+)@.+$")
     268            string(REPLACE "@" "_" TP "${TP}")
     269            set(${TP}_TEST_BASENAME "${CMAKE_MATCH_1}")
     270        else()
     271            set(${TP}_TEST_BASENAME "${T}")
     272        endif()
     273        add_executable(${TP} ${${TP}_TEST_BASENAME}-test.c ${${T}-test_ADD_SOURCES})
    266274        target_link_libraries(${TP} ${TR_NAME} ${TR_NAME}-test)
     275        if(DEFINED ${T}-test_DEFINITIONS)
     276            target_compile_definitions(${TP} PRIVATE ${${T}-test_DEFINITIONS})
     277        endif()
    267278        add_test(NAME ${T} COMMAND ${TP})
    268279        set_property(TARGET ${TP} PROPERTY FOLDER "UnitTests")
  • trunk/libtransmission/Makefile.am

    r14660 r14674  
    189189  utils-test \
    190190  variant-test \
    191   watchdir-test
     191  watchdir-test \
     192  watchdir-generic-test
    192193
    193194noinst_PROGRAMS = $(TESTS)
     
    290291watchdir_test_LDFLAGS = ${apps_ldflags}
    291292
     293watchdir_generic_test_SOURCES = watchdir-test.c $(TEST_SOURCES)
     294watchdir_generic_test_LDADD = ${apps_ldadd}
     295watchdir_generic_test_LDFLAGS = ${apps_ldflags}
     296watchdir_generic_test_CPPFLAGS = -DWATCHDIR_TEST_FORCE_GENERIC $(AM_CPPFLAGS)
     297
    292298rename_test_SOURCES = rename-test.c $(TEST_SOURCES)
    293299rename_test_LDADD = ${apps_ldadd}
  • trunk/libtransmission/watchdir-test.c

    r14651 r14674  
    9898}
    9999
     100tr_watchdir_t
     101create_watchdir (const char        * path,
     102                 tr_watchdir_cb      callback,
     103                 void              * callback_user_data,
     104                 struct event_base * event_base)
     105{
     106#ifdef WATCHDIR_TEST_FORCE_GENERIC
     107  const bool force_generic = true;
     108#else
     109  const bool force_generic = false;
     110#endif
     111
     112  return tr_watchdir_new (path, callback, callback_user_data, event_base, force_generic);
     113}
     114
    100115/***
    101116****
     
    110125  ev_base = event_base_new();
    111126
    112   wd = tr_watchdir_new (test_dir, &callback, NULL, ev_base);
     127  wd = create_watchdir (test_dir, &callback, NULL, ev_base);
    113128  check (wd != NULL);
    114129  check (tr_sys_path_is_same (test_dir, tr_watchdir_get_path (wd), NULL));
     
    137152    reset_callback_data (&wd_data, TR_WATCHDIR_ACCEPT);
    138153
    139     tr_watchdir_t wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
     154    tr_watchdir_t wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
    140155    check (wd != NULL);
    141156
     
    154169    reset_callback_data (&wd_data, TR_WATCHDIR_ACCEPT);
    155170
    156     tr_watchdir_t wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
     171    tr_watchdir_t wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
    157172    check (wd != NULL);
    158173
     
    185200
    186201  reset_callback_data (&wd_data, TR_WATCHDIR_ACCEPT);
    187   wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
     202  wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
    188203  check (wd != NULL);
    189204
     
    240255
    241256  reset_callback_data (&wd1_data, TR_WATCHDIR_ACCEPT);
    242   wd1 = tr_watchdir_new (dir1, &callback, &wd1_data, ev_base);
     257  wd1 = create_watchdir (dir1, &callback, &wd1_data, ev_base);
    243258  check (wd1 != NULL);
    244259
    245260  reset_callback_data (&wd2_data, TR_WATCHDIR_ACCEPT);
    246   wd2 = tr_watchdir_new (dir2, &callback, &wd2_data, ev_base);
     261  wd2 = create_watchdir (dir2, &callback, &wd2_data, ev_base);
    247262  check (wd2 != NULL);
    248263
     
    348363
    349364  reset_callback_data (&wd_data, TR_WATCHDIR_RETRY);
    350   wd = tr_watchdir_new (test_dir, &callback, &wd_data, ev_base);
     365  wd = create_watchdir (test_dir, &callback, &wd_data, ev_base);
    351366  check (wd != NULL);
    352367
  • trunk/libtransmission/watchdir.c

    r14651 r14674  
    233233                 tr_watchdir_cb      callback,
    234234                 void              * callback_user_data,
    235                  struct event_base * event_base)
     235                 struct event_base * event_base,
     236                 bool                force_generic)
    236237{
    237238  tr_watchdir_t handle;
     
    244245  tr_watchdir_retries_init (&handle->active_retries);
    245246
     247  if (!force_generic)
     248    {
    246249#ifdef WITH_INOTIFY
    247   if (handle->backend == NULL)
    248     handle->backend = tr_watchdir_inotify_new (handle);
     250      if (handle->backend == NULL)
     251        handle->backend = tr_watchdir_inotify_new (handle);
    249252#endif
    250253#ifdef WITH_KQUEUE
    251   if (handle->backend == NULL)
    252     handle->backend = tr_watchdir_kqueue_new (handle);
     254      if (handle->backend == NULL)
     255        handle->backend = tr_watchdir_kqueue_new (handle);
    253256#endif
    254257#ifdef _WIN32
    255   if (handle->backend == NULL)
    256     handle->backend = tr_watchdir_win32_new (handle);
     258      if (handle->backend == NULL)
     259        handle->backend = tr_watchdir_win32_new (handle);
    257260#endif
     261    }
    258262
    259263  if (handle->backend == NULL)
  • trunk/libtransmission/watchdir.h

    r14651 r14674  
    3636                                      tr_watchdir_cb      callback,
    3737                                      void              * callback_user_data,
    38                                       struct event_base * event_base);
     38                                      struct event_base * event_base,
     39                                      bool                force_generic);
    3940
    4041void            tr_watchdir_free     (tr_watchdir_t       handle);
Note: See TracChangeset for help on using the changeset viewer.