From 95236d1f3e219da048df5039eaecdaac10e6bff6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 21 Feb 2010 00:24:01 +0000 Subject: [PATCH] (trunk daemon) #2943 "watch.c matches everything containing '.torrent'" -- use Longinus00's patch to fix this in trunk for 1.91 --- daemon/watch.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon/watch.c b/daemon/watch.c index c1941e417..f4f24cacb 100644 --- a/daemon/watch.c +++ b/daemon/watch.c @@ -40,6 +40,18 @@ struct dtr_watchdir #endif }; +static tr_bool +str_has_suffix( const char *str, const char *suffix ) +{ + const size_t str_len = strlen( str ); + const size_t suffix_len = strlen( suffix ); + + if( str_len < suffix_len ) + return FALSE; + + return !strncasecmp( str + str_len - suffix_len, suffix, suffix_len ); +} + /*** **** INOTIFY IMPLEMENTATION ***/ @@ -99,7 +111,7 @@ watchdir_update_impl( dtr_watchdir * w ) int len = read( fd, buf, sizeof( buf ) ); while (i < len) { struct inotify_event * event = (struct inotify_event *) &buf[i]; - if( strstr( event->name, ".torrent" ) != NULL ) + if( str_has_suffix( event->name, ".torrent" ) ) { tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", event->name, w->dir ); w->callback( w->session, w->dir, event->name ); @@ -170,7 +182,7 @@ watchdir_update_impl( dtr_watchdir * w ) if( !d->d_name || *d->d_name=='.' ) /* skip dotfiles */ continue; - if( !strstr( d->d_name, ".torrent" ) ) /* skip non-torrents */ + if( !str_has_suffix( event->name, ".torrent" ) ) /* skip non-torrents */ continue; len = strlen( d->d_name );