Changeset 10295


Ignore:
Timestamp:
Feb 27, 2010, 10:13:29 PM (12 years ago)
Author:
charles
Message:

(trunk daemon) #2949 "standardize inotify watchdir implementation" -- fixed in trunk for 1.92. Thanks to Longinus00 for another patch :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/watch.c

    r10287 r10295  
    1717  #include <sys/types.h> /* stat */
    1818  #include <sys/stat.h> /* stat */
    19   #include <dirent.h> /* readdir */
    2019  #include <event.h> /* evbuffer */
    2120#endif
     
    2322#include <errno.h>
    2423#include <string.h> /* strstr */
     24
     25#include <dirent.h> /* readdir */
    2526
    2627#include <libtransmission/transmission.h>
     
    6667#define BUF_LEN (EVENT_BATCH_COUNT * (EVENT_SIZE + 16) + 2048)
    6768
    68 #define DTR_INOTIFY_MASK (IN_CLOSE_WRITE|IN_MOVED_TO)
     69#define DTR_INOTIFY_MASK (IN_CLOSE_WRITE|IN_MOVED_TO|IN_ONLYDIR)
    6970
    7071static void
     
    7273{
    7374    int i;
     75    DIR * odir;
    7476    w->inotify_fd = inotify_init( );
    7577    tr_inf( "Using inotify to watch directory \"%s\"", w->dir );
    7678    i = inotify_add_watch( w->inotify_fd, w->dir, DTR_INOTIFY_MASK );
     79
    7780    if( i < 0 )
     81    {
    7882        tr_err( "Unable to watch \"%s\": %s", w->dir, strerror (errno) );
     83    }
     84    else if(( odir = opendir( w->dir )))
     85    {
     86        struct dirent * d;
     87
     88        while(( d = readdir( odir )))
     89        {
     90            const char * name = d->d_name;
     91
     92            if( !name || *name=='.' ) /* skip dotfiles */
     93                continue;
     94            if( !str_has_suffix( name, ".torrent" ) ) /* skip non-torrents */
     95                continue;
     96
     97            tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir );
     98            w->callback( w->session, w->dir, name );
     99        }
     100
     101        closedir( odir );
     102    }
     103
    79104}
    80105static void
Note: See TracChangeset for help on using the changeset viewer.