Changeset 12296


Ignore:
Timestamp:
Apr 2, 2011, 7:36:34 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) tr_torrentGetFileMTime() used to require two stat() calls.. now it only requires one.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r12228 r12296  
    7171
    7272        /* see if the file exists... */
    73         if( !tr_torrentFindFile2( tor, fileIndex, &base, &subpath ) )
     73        if( !tr_torrentFindFile2( tor, fileIndex, &base, &subpath, NULL ) )
    7474        {
    7575            /* we can't read a file that doesn't exist... */
  • trunk/libtransmission/torrent.c

    r12295 r12296  
    765765
    766766    for( i=0; i<tor->info.fileCount; ++i )
    767         if( tr_torrentFindFile2( tor, i, NULL, NULL ) )
     767        if( tr_torrentFindFile2( tor, i, NULL, NULL, NULL ) )
    768768            return true;
    769769
     
    23722372tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i )
    23732373{
    2374     struct stat sb;
    23752374    time_t mtime = 0;
    2376     char * path = tr_torrentFindFile( tor, i );
    2377 
    2378     if( ( path != NULL ) && !stat( path, &sb ) && S_ISREG( sb.st_mode ) )
    2379     {
    2380 #ifdef SYS_DARWIN
    2381         mtime = sb.st_mtimespec.tv_sec;
    2382 #else
    2383         mtime = sb.st_mtime;
    2384 #endif
    2385     }
    2386 
    2387     tr_free( path );
     2375    tr_torrentFindFile2( tor, i, NULL, NULL, &mtime );
    23882376    return mtime;
    23892377}
     
    28332821            const char * oldbase;
    28342822            char * sub;
    2835             if( tr_torrentFindFile2( tor, i, &oldbase, &sub ) )
     2823            if( tr_torrentFindFile2( tor, i, &oldbase, &sub, NULL ) )
    28362824            {
    28372825                char * oldpath = tr_buildPath( oldbase, sub, NULL );
     
    29432931     * metadata -- for example, if it had the ".part" suffix appended to
    29442932     * it until now -- then rename it to match the one in the metadata */
    2945     if( tr_torrentFindFile2( tor, fileNum, &base, &sub ) )
     2933    if( tr_torrentFindFile2( tor, fileNum, &base, &sub, NULL ) )
    29462934    {
    29472935        if( strcmp( sub, f->name ) )
     
    29662954
    29672955static bool
    2968 fileExists( const char * filename )
     2956fileExists( const char * filename, time_t * mtime )
    29692957{
    29702958    struct stat sb;
    29712959    const bool ok = !stat( filename, &sb );
     2960
     2961    if( ok && ( mtime != NULL ) )
     2962    {
     2963#ifdef SYS_DARWIN
     2964        *mtime = sb.st_mtimespec.tv_sec;
     2965#else
     2966        *mtime = sb.st_mtime;
     2967#endif
     2968    }
     2969
    29722970    return ok;
    29732971}
     
    29752973bool
    29762974tr_torrentFindFile2( const tr_torrent * tor, tr_file_index_t fileNum,
    2977                      const char ** base, char ** subpath )
     2975                     const char ** base, char ** subpath, time_t * mtime )
    29782976{
    29792977    char * part = NULL;
     
    29892987    if( b == NULL ) {
    29902988        char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
    2991         if( fileExists( filename ) ) {
     2989        if( fileExists( filename, mtime ) ) {
    29922990            b = tor->downloadDir;
    29932991            s = file->name;
     
    29982996    if( ( b == NULL ) && ( tor->incompleteDir != NULL ) ) {
    29992997        char * filename = tr_buildPath( tor->incompleteDir, file->name, NULL );
    3000         if( fileExists( filename ) ) {
     2998        if( fileExists( filename, mtime ) ) {
    30012999            b = tor->incompleteDir;
    30023000            s = file->name;
     
    30103008    if( ( b == NULL ) && ( tor->incompleteDir != NULL ) ) {
    30113009        char * filename = tr_buildPath( tor->incompleteDir, part, NULL );
    3012         if( fileExists( filename ) ) {
     3010        if( fileExists( filename, mtime ) ) {
    30133011            b = tor->incompleteDir;
    30143012            s = part;
     
    30193017    if( b == NULL) {
    30203018        char * filename = tr_buildPath( tor->downloadDir, part, NULL );
    3021         if( fileExists( filename ) ) {
     3019        if( fileExists( filename, mtime ) ) {
    30223020            b = tor->downloadDir;
    30233021            s = part;
     
    30423040    const char * base;
    30433041
    3044     if( tr_torrentFindFile2( tor, fileNum, &base, &subpath ) )
     3042    if( tr_torrentFindFile2( tor, fileNum, &base, &subpath, NULL ) )
    30453043    {
    30463044        ret = tr_buildPath( base, subpath, NULL );
     
    30613059    else if( !tr_torrentHasMetadata( tor ) ) /* no files to find */
    30623060        dir = tor->incompleteDir;
    3063     else if( !tr_torrentFindFile2( tor, 0, &dir, NULL ) )
     3061    else if( !tr_torrentFindFile2( tor, 0, &dir, NULL, NULL ) )
    30643062        dir = tor->incompleteDir;
    30653063
  • trunk/libtransmission/torrent.h

    r12281 r12296  
    396396 */
    397397bool tr_torrentFindFile2( const tr_torrent *, tr_file_index_t fileNo,
    398                           const char ** base, char ** subpath );
     398                          const char ** base, char ** subpath, time_t * mtime );
    399399
    400400
Note: See TracChangeset for help on using the changeset viewer.