1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

(trunk libT) tr_torrentGetFileMTime(): if the file being looked at is aleady open in fdlimit's file cache, use that cached handle instead of deriving our own.

This commit is contained in:
Jordan Lee 2011-04-28 18:40:46 +00:00
parent b93bef2712
commit 513a3fcc1d
3 changed files with 35 additions and 8 deletions

View file

@ -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 )
{

View file

@ -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.
*

View file

@ -2372,6 +2372,7 @@ time_t
tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i )
{
time_t mtime = 0;
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;
}