(trunk) #3262 "problems with '.' as the first character in a .torrent's filename" -- fixed in trunk for 2.00
This commit is contained in:
parent
9704a8637e
commit
0ad06c50e8
|
@ -41,18 +41,6 @@ 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
|
||||
***/
|
||||
|
@ -97,9 +85,7 @@ watchdir_new_impl( dtr_watchdir * w )
|
|||
{
|
||||
const char * name = d->d_name;
|
||||
|
||||
if( !name || *name=='.' ) /* skip dotfiles */
|
||||
continue;
|
||||
if( !str_has_suffix( name, ".torrent" ) ) /* skip non-torrents */
|
||||
if( !tr_str_has_suffix( name, ".torrent" ) ) /* skip non-torrents */
|
||||
continue;
|
||||
|
||||
tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir );
|
||||
|
@ -149,7 +135,7 @@ watchdir_update_impl( dtr_watchdir * w )
|
|||
while (i < len) {
|
||||
struct inotify_event * event = (struct inotify_event *) &buf[i];
|
||||
const char * name = event->name;
|
||||
if( str_has_suffix( name, ".torrent" ) )
|
||||
if( tr_str_has_suffix( name, ".torrent" ) )
|
||||
{
|
||||
tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir );
|
||||
w->callback( w->session, w->dir, name );
|
||||
|
|
|
@ -339,11 +339,11 @@ moveFiles( const char * oldDir,
|
|||
struct dirent * dirp;
|
||||
while( ( dirp = readdir( dirh ) ) )
|
||||
{
|
||||
if( strcmp( dirp->d_name,
|
||||
"." ) && strcmp( dirp->d_name, ".." ) )
|
||||
const char * name = dirp->d_name;
|
||||
if( name && strcmp( name, "." ) && strcmp( name, ".." ) )
|
||||
{
|
||||
char * o = tr_buildPath( oldDir, dirp->d_name, NULL );
|
||||
char * n = tr_buildPath( newDir, dirp->d_name, NULL );
|
||||
char * o = tr_buildPath( oldDir, name, NULL );
|
||||
char * n = tr_buildPath( newDir, name, NULL );
|
||||
rename( o, n );
|
||||
++count;
|
||||
tr_free( n );
|
||||
|
|
|
@ -1720,8 +1720,7 @@ tr_sessionLoadTorrents( tr_session * session,
|
|||
struct dirent *d;
|
||||
for( d = readdir( odir ); d != NULL; d = readdir( odir ) )
|
||||
{
|
||||
if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles, ., and ..
|
||||
*/
|
||||
if( tr_str_has_suffix( d->d_name, ".torrent" ) )
|
||||
{
|
||||
tr_torrent * tor;
|
||||
char * path = tr_buildPath( dirname, d->d_name, NULL );
|
||||
|
@ -2103,7 +2102,7 @@ metainfoLookupInit( tr_session * session )
|
|||
struct dirent *d;
|
||||
while(( d = readdir( odir )))
|
||||
{
|
||||
if( d->d_name && d->d_name[0] != '.' )
|
||||
if( tr_str_has_suffix( d->d_name, ".torrent" ) )
|
||||
{
|
||||
tr_info inf;
|
||||
char * path = tr_buildPath( dirname, d->d_name, NULL );
|
||||
|
|
|
@ -2376,7 +2376,7 @@ walkLocalData( const tr_torrent * tor,
|
|||
struct dirent *d;
|
||||
tr_ptrArrayInsertSorted( folders, tr_strdup( buf ), vstrcmp );
|
||||
for( d = readdir( odir ); d != NULL; d = readdir( odir ) )
|
||||
if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles */
|
||||
if( d->d_name && strcmp( d->d_name, "." ) && strcmp( d->d_name, ".." ) )
|
||||
walkLocalData( tor, root, buf, d->d_name, torrentFiles, folders, dirtyFolders );
|
||||
closedir( odir );
|
||||
}
|
||||
|
|
|
@ -773,6 +773,25 @@ tr_strstrip( char * str )
|
|||
return str;
|
||||
}
|
||||
|
||||
tr_bool
|
||||
tr_str_has_suffix( const char *str, const char *suffix )
|
||||
{
|
||||
size_t str_len;
|
||||
size_t suffix_len;
|
||||
|
||||
if( !str )
|
||||
return FALSE;
|
||||
if( !suffix )
|
||||
return TRUE;
|
||||
|
||||
str_len = strlen( str );
|
||||
suffix_len = strlen( suffix );
|
||||
if( str_len < suffix_len )
|
||||
return FALSE;
|
||||
|
||||
return !strncasecmp( str + str_len - suffix_len, suffix, suffix_len );
|
||||
}
|
||||
|
||||
/****
|
||||
*****
|
||||
****/
|
||||
|
|
|
@ -400,6 +400,10 @@ const char* tr_strerror( int );
|
|||
@return the stripped string */
|
||||
char* tr_strstrip( char * str );
|
||||
|
||||
/** @brief Returns true if the string ends with the specified case-insensitive suffix */
|
||||
tr_bool tr_str_has_suffix( const char *str, const char *suffix );
|
||||
|
||||
|
||||
/** @brief Portability wrapper for memmem() that uses the system implementation if available */
|
||||
const char* tr_memmem( const char * haystack, size_t haystack_len,
|
||||
const char * needle, size_t needle_len );
|
||||
|
|
Loading…
Reference in New Issue