mirror of
https://github.com/transmission/transmission
synced 2024-12-23 08:13:27 +00:00
(trunk daemon) #2949 "standardize inotify watchdir implementation" -- fixed in trunk for 1.92. Thanks to Longinus00 for another patch :)
This commit is contained in:
parent
a5c714d16b
commit
2060557f6d
1 changed files with 27 additions and 2 deletions
|
@ -16,13 +16,14 @@
|
|||
#else
|
||||
#include <sys/types.h> /* stat */
|
||||
#include <sys/stat.h> /* stat */
|
||||
#include <dirent.h> /* readdir */
|
||||
#include <event.h> /* evbuffer */
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h> /* strstr */
|
||||
|
||||
#include <dirent.h> /* readdir */
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/utils.h> /* tr_buildPath(), tr_inf() */
|
||||
#include "watch.h"
|
||||
|
@ -65,17 +66,41 @@ str_has_suffix( const char *str, const char *suffix )
|
|||
/* reasonable guess as to size of 50 events */
|
||||
#define BUF_LEN (EVENT_BATCH_COUNT * (EVENT_SIZE + 16) + 2048)
|
||||
|
||||
#define DTR_INOTIFY_MASK (IN_CLOSE_WRITE|IN_MOVED_TO)
|
||||
#define DTR_INOTIFY_MASK (IN_CLOSE_WRITE|IN_MOVED_TO|IN_ONLYDIR)
|
||||
|
||||
static void
|
||||
watchdir_new_impl( dtr_watchdir * w )
|
||||
{
|
||||
int i;
|
||||
DIR * odir;
|
||||
w->inotify_fd = inotify_init( );
|
||||
tr_inf( "Using inotify to watch directory \"%s\"", w->dir );
|
||||
i = inotify_add_watch( w->inotify_fd, w->dir, DTR_INOTIFY_MASK );
|
||||
|
||||
if( i < 0 )
|
||||
{
|
||||
tr_err( "Unable to watch \"%s\": %s", w->dir, strerror (errno) );
|
||||
}
|
||||
else if(( odir = opendir( w->dir )))
|
||||
{
|
||||
struct dirent * d;
|
||||
|
||||
while(( d = readdir( odir )))
|
||||
{
|
||||
const char * name = d->d_name;
|
||||
|
||||
if( !name || *name=='.' ) /* skip dotfiles */
|
||||
continue;
|
||||
if( !str_has_suffix( name, ".torrent" ) ) /* skip non-torrents */
|
||||
continue;
|
||||
|
||||
tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir );
|
||||
w->callback( w->session, w->dir, name );
|
||||
}
|
||||
|
||||
closedir( odir );
|
||||
}
|
||||
|
||||
}
|
||||
static void
|
||||
watchdir_free_impl( dtr_watchdir * w )
|
||||
|
|
Loading…
Reference in a new issue