Changeset 7971


Ignore:
Timestamp:
Feb 27, 2009, 9:49:31 PM (13 years ago)
Author:
charles
Message:

(trunk daemon) experimental commit for part of #1483: adding a WatchDir? to transmission-daemon. I don't know if this will work out because of (1) any possible C/C++ issues, and (2) maybe some embedded systems don't have inotify and/or kqueue?

Location:
trunk
Files:
18 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r7961 r7971  
    338338                 libtransmission/Makefile
    339339                 third-party/Makefile
     340                 third-party/filewatcher/Makefile
    340341                 third-party/miniupnp/Makefile
    341342                 third-party/libnatpmp/Makefile
  • trunk/daemon/Makefile.am

    r7087 r7971  
    2020LDADD = \
    2121    $(top_builddir)/libtransmission/libtransmission.a \
     22    $(top_builddir)/third-party/filewatcher/libfilewatcher.a -lstdc++ \
    2223    $(top_builddir)/third-party/miniupnp/libminiupnp.a \
    2324    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
  • trunk/daemon/daemon.c

    r7785 r7971  
    3232#include <libtransmission/version.h>
    3333
     34#include <filewatcher/file-watcher.h>
     35
    3436#define MY_NAME "transmission-daemon"
     37
     38#define PREF_KEY_DIR_WATCH          "watch-dir"
     39#define PREF_KEY_DIR_WATCH_ENABLED  "watch-dir-enabled"
     40
    3541
    3642static int           closing = FALSE;
     
    5965    { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
    6066    { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
     67    { 'c', "watch-dir", "Directory to watch for new .torrent files", "c", 1, "<directory>" },
     68    { 'C', "no-watch-dir", "Disable the watch-dir", "C", 0, NULL },
    6169    { 'd', "dump-settings", "Dump the settings and exit", "d", 0, NULL },
    6270    { 'f', "foreground", "Run in the foreground instead of daemonizing", "f", 0, NULL },
     
    173181}
    174182
     183static void
     184dirChangedCB( CFW_Watch * watch UNUSED, const char * directory, const char * filename, CFW_Action action, void * userData )
     185{
     186    if( action & ( CFW_ACTION_ADD | CFW_ACTION_DELETE ) )
     187    {
     188        int err;
     189        char * path = tr_buildPath( directory, filename, NULL );
     190        tr_session * session = userData;
     191        tr_ctor * ctor = tr_ctorNew( session );
     192        tr_ctorSetMetainfoFromFile( ctor, path );
     193        tr_torrentNew( session, ctor, &err );
     194        tr_free( path );
     195    }
     196}
    175197
    176198int
    177 main( int     argc,
    178       char ** argv )
     199main( int argc, char ** argv )
    179200{
    180201    int c;
     
    185206    tr_bool dumpSettings = FALSE;
    186207    const char * configDir = NULL;
     208    CFW_Watch * watch = NULL;
    187209
    188210    signal( SIGINT, gotsig );
     
    211233            case 'B': tr_bencDictAddInt( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, 0 );
    212234                      break;
     235            case 'c': tr_bencDictAddStr( &settings, PREF_KEY_DIR_WATCH, optarg );
     236                      tr_bencDictAddInt( &settings, PREF_KEY_DIR_WATCH_ENABLED, 1 );
     237                      break;
     238            case 'C': tr_bencDictAddInt( &settings, PREF_KEY_DIR_WATCH_ENABLED, 0 );
     239                      break;
    213240            case 'd': dumpSettings = TRUE;
    214241                      break;
     
    276303        tr_ninf( MY_NAME, "requiring authentication" );
    277304
     305    /* maybe add a watchdir */
     306    {
     307        int64_t doWatch;
     308        const char * watchDir;
     309        if( tr_bencDictFindInt( &settings, PREF_KEY_DIR_WATCH_ENABLED, &doWatch )
     310            && doWatch
     311            && tr_bencDictFindStr( &settings, PREF_KEY_DIR_WATCH, &watchDir )
     312            && watchDir
     313            && *watchDir )
     314        {
     315            tr_ninf( MY_NAME, "watching \"%s\" for added .torrent files", watchDir );
     316            watch = cfw_addWatch( watchDir, dirChangedCB, mySession );
     317        }
     318    }
     319
    278320    /* load the torrents */
    279321    {
     
    284326    }
    285327
    286     while( !closing )
     328    while( !closing ) {
    287329        tr_wait( 1000 ); /* sleep one second */
     330        if( watch )
     331            cfw_update( watch );
     332    }
    288333
    289334    /* shutdown */
    290335    printf( "Closing transmission session..." );
     336    if( watch )
     337        cfw_removeWatch( watch );
    291338    tr_sessionSaveSettings( mySession, configDir, &settings );
    292339    tr_sessionClose( mySession );
  • trunk/daemon/transmission-daemon.1

    r7785 r7971  
    1212.Op Fl a Ar x.x.x.x,...
    1313.Op Fl b | B
     14.Op Fl c Ar directory
     15.Op Fl C
    1416.Op Fl f
    1517.Op Fl g Ar directory
     
    4648Enable peer blocklists.  Transmission understands the bluetack blocklist file format.
    4749New blocklists can be added by copying them into the config-dir's "blocklists" subdirectory.
     50
     51.It Fl c Ar directory
     52Directory to watch for new .torrent files to be added.  As they are added to this directory,
     53the daemon will load them into Transmission.
     54
     55.It Fl C
     56Do not watch for new .torrent files.
    4857
    4958.It Fl B Fl -no-blocklist
  • trunk/third-party/Makefile.am

    r6797 r7971  
    11SUBDIRS = \
     2    filewatcher \
    23    libevent \
    34    libnatpmp \
Note: See TracChangeset for help on using the changeset viewer.