]> granicus.if.org Git - transmission/commitdiff
(trunk) #3262 "problems with '.' as the first character in a .torrent's filename...
authorCharles Kerr <charles@transmissionbt.com>
Mon, 7 Jun 2010 14:25:31 +0000 (14:25 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 7 Jun 2010 14:25:31 +0000 (14:25 +0000)
daemon/watch.c
libtransmission/platform.c
libtransmission/session.c
libtransmission/torrent.c
libtransmission/utils.c
libtransmission/utils.h

index e53ddc1ef35e2997dfe4c6f934d1650a0b217001..de2f0399839c4e5676b20ce78d7506ad25979912 100644 (file)
@@ -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 );
index 70e3776eb5df6e8a7a33e015bead70f9382bed57..09f1b057d38f3583aaf64da38c8470da32ea9fe3 100644 (file)
@@ -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 );
index b24ac7a2dab41835f2c5fa59a5f5cdf596aceed7..afb5867266d1bb7e3430f65c013ad61b64561f8e 100644 (file)
@@ -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 );
index 87aa068b9ad5885d5ad1822c095facb8c978409e..83fd73ac08492395d9904052faa21f01a680e8a5 100644 (file)
@@ -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 );
         }
index 128cb222d863059e9977d036eb279c2a74c2a598..d28eea5c0754edd681c0252901dd6eb820035930 100644 (file)
@@ -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 );
+}
+
 /****
 *****
 ****/
index 6c1939ea073046fbcb01cac087edb819db39e973..85df9b058d72e843eee6c76191cd605f6c7dea65 100644 (file)
@@ -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 );