Changeset 13362


Ignore:
Timestamp:
Jul 1, 2012, 3:05:36 AM (9 years ago)
Author:
jordan
Message:

(trunk libT) move torrent.c's private function fileExists() to the utility function tr_fileExists() so that it can also be used by stats.c

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r13361 r13362  
    27222722}
    27232723
    2724 static bool fileExists( const char * filename, time_t * optional_mtime );
    2725 
    27262724/**
    27272725 * This convoluted code does something (seemingly) simple:
     
    27622760    {
    27632761        char * filename = tr_buildPath( top, tor->info.files[f].name, NULL );
    2764         if( !fileExists( filename, NULL ) ) {
     2762        if( !tr_fileExists( filename, NULL ) ) {
    27652763                char * partial = tr_torrentBuildPartial( tor, f );
    27662764                tr_free( filename );
    27672765                filename = tr_buildPath( top, partial, NULL );
    27682766                tr_free( partial );
    2769                 if( !fileExists( filename, NULL ) ) {
     2767                if( !tr_fileExists( filename, NULL ) ) {
    27702768                        tr_free( filename );
    27712769                        filename = NULL;
     
    28142812    {
    28152813        char * walk = tr_strdup( tr_ptrArrayNth( &files, i ) );
    2816         while( fileExists( walk, NULL ) && !tr_is_same_file( tmpdir, walk ) )
     2814        while( tr_fileExists( walk, NULL ) && !tr_is_same_file( tmpdir, walk ) )
    28172815        {
    28182816            char * tmp = tr_dirname( walk );
     
    30543052***/
    30553053
    3056 #ifdef SYS_DARWIN
    3057  #define TR_STAT_MTIME(sb) ((sb).st_mtimespec.tv_sec)
    3058 #else
    3059  #define TR_STAT_MTIME(sb) ((sb).st_mtime)
    3060 #endif
    3061 
    3062 
    3063 static bool
    3064 fileExists( const char * filename, time_t * mtime )
    3065 {
    3066     struct stat sb;
    3067     const bool ok = !stat( filename, &sb );
    3068 
    3069     if( ok && ( mtime != NULL ) )
    3070         *mtime = TR_STAT_MTIME( sb );
    3071 
    3072     return ok;
    3073 }
    3074 
    30753054bool
    30763055tr_torrentFindFile2( const tr_torrent * tor, tr_file_index_t fileNum,
     
    30893068    if( b == NULL ) {
    30903069        char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
    3091         if( fileExists( filename, mtime ) ) {
     3070        if( tr_fileExists( filename, mtime ) ) {
    30923071            b = tor->downloadDir;
    30933072            s = file->name;
     
    30983077    if( ( b == NULL ) && ( tor->incompleteDir != NULL ) ) {
    30993078        char * filename = tr_buildPath( tor->incompleteDir, file->name, NULL );
    3100         if( fileExists( filename, mtime ) ) {
     3079        if( tr_fileExists( filename, mtime ) ) {
    31013080            b = tor->incompleteDir;
    31023081            s = file->name;
     
    31103089    if( ( b == NULL ) && ( tor->incompleteDir != NULL ) ) {
    31113090        char * filename = tr_buildPath( tor->incompleteDir, part, NULL );
    3112         if( fileExists( filename, mtime ) ) {
     3091        if( tr_fileExists( filename, mtime ) ) {
    31133092            b = tor->incompleteDir;
    31143093            s = part;
     
    31193098    if( b == NULL) {
    31203099        char * filename = tr_buildPath( tor->downloadDir, part, NULL );
    3121         if( fileExists( filename, mtime ) ) {
     3100        if( tr_fileExists( filename, mtime ) ) {
    31223101            b = tor->downloadDir;
    31233102            s = part;
  • trunk/libtransmission/utils.c

    r13301 r13362  
    639639}
    640640
     641#ifdef SYS_DARWIN
     642 #define TR_STAT_MTIME(sb) ((sb).st_mtimespec.tv_sec)
     643#else
     644 #define TR_STAT_MTIME(sb) ((sb).st_mtime)
     645#endif
     646
     647bool
     648tr_fileExists( const char * filename, time_t * mtime )
     649{
     650    struct stat sb;
     651    const bool ok = !stat( filename, &sb );
     652
     653    if( ok && ( mtime != NULL ) )
     654        *mtime = TR_STAT_MTIME( sb );
     655
     656    return ok;
     657}
     658
    641659/****
    642660*****
  • trunk/libtransmission/utils.h

    r13084 r13362  
    239239char* tr_buildPath( const char * first_element, ... ) TR_GNUC_NULL_TERMINATED
    240240                                                      TR_GNUC_MALLOC;
     241
     242bool tr_fileExists( const char * filename, time_t * mtime );
     243
    241244
    242245struct event;
Note: See TracChangeset for help on using the changeset viewer.