diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 780afb898..841e00127 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -561,6 +561,25 @@ tr_fdFileGetCached( tr_session * s, int torrent_id, tr_file_index_t i, bool writ return o->fd; } +#ifdef SYS_DARWIN + #define TR_STAT_MTIME(sb) ((sb).st_mtimespec.tv_sec) +#else + #define TR_STAT_MTIME(sb) ((sb).st_mtime) +#endif + +bool +tr_fdFileGetCachedMTime( tr_session * s, int torrent_id, tr_file_index_t i, time_t * mtime ) +{ + bool success; + struct stat sb; + struct tr_cached_file * o = fileset_lookup( get_fileset( s ), torrent_id, i ); + + if(( success = ( o != NULL ) && !fstat( o->fd, &sb ))) + *mtime = TR_STAT_MTIME( sb ); + + return success; +} + void tr_fdTorrentClose( tr_session * session, int torrent_id ) { diff --git a/libtransmission/fdlimit.h b/libtransmission/fdlimit.h index 1cc3b2481..a459c26d8 100644 --- a/libtransmission/fdlimit.h +++ b/libtransmission/fdlimit.h @@ -81,6 +81,12 @@ int tr_fdFileGetCached( tr_session * session, tr_file_index_t file_num, bool doWrite ); +bool tr_fdFileGetCachedMTime( tr_session * session, + int torrent_id, + tr_file_index_t file_num, + time_t * mtime ); + + /** * Closes a file that's being held by our file repository. * diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 0e2ca0132..b4e942ffe 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -2372,7 +2372,8 @@ time_t tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i ) { time_t mtime = 0; - tr_torrentFindFile2( tor, i, NULL, NULL, &mtime ); + if( !tr_fdFileGetCachedMTime( tor->session, tor->uniqueId, i, &mtime ) ) + tr_torrentFindFile2( tor, i, NULL, NULL, &mtime ); return mtime; } @@ -2952,6 +2953,13 @@ tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum ) **** ***/ +#ifdef SYS_DARWIN + #define TR_STAT_MTIME(sb) ((sb).st_mtimespec.tv_sec) +#else + #define TR_STAT_MTIME(sb) ((sb).st_mtime) +#endif + + static bool fileExists( const char * filename, time_t * mtime ) { @@ -2959,13 +2967,7 @@ fileExists( const char * filename, time_t * mtime ) const bool ok = !stat( filename, &sb ); if( ok && ( mtime != NULL ) ) - { -#ifdef SYS_DARWIN - *mtime = sb.st_mtimespec.tv_sec; -#else - *mtime = sb.st_mtime; -#endif - } + *mtime = TR_STAT_MTIME( sb ); return ok; }