tr_file_index_t i;
for( i=0; i<tor->info.fileCount; ++i )
- if( tr_torrentFindFile2( tor, i, NULL, NULL ) )
+ if( tr_torrentFindFile2( tor, i, NULL, NULL, NULL ) )
return true;
return false;
time_t
tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i )
{
- struct stat sb;
time_t mtime = 0;
- char * path = tr_torrentFindFile( tor, i );
-
- if( ( path != NULL ) && !stat( path, &sb ) && S_ISREG( sb.st_mode ) )
- {
-#ifdef SYS_DARWIN
- mtime = sb.st_mtimespec.tv_sec;
-#else
- mtime = sb.st_mtime;
-#endif
- }
-
- tr_free( path );
+ tr_torrentFindFile2( tor, i, NULL, NULL, &mtime );
return mtime;
}
const tr_file * f = &tor->info.files[i];
const char * oldbase;
char * sub;
- if( tr_torrentFindFile2( tor, i, &oldbase, &sub ) )
+ if( tr_torrentFindFile2( tor, i, &oldbase, &sub, NULL ) )
{
char * oldpath = tr_buildPath( oldbase, sub, NULL );
char * newpath = tr_buildPath( location, sub, NULL );
/* if the torrent's current filename isn't the same as the one in the
* metadata -- for example, if it had the ".part" suffix appended to
* it until now -- then rename it to match the one in the metadata */
- if( tr_torrentFindFile2( tor, fileNum, &base, &sub ) )
+ if( tr_torrentFindFile2( tor, fileNum, &base, &sub, NULL ) )
{
if( strcmp( sub, f->name ) )
{
***/
static bool
-fileExists( const char * filename )
+fileExists( const char * filename, time_t * mtime )
{
struct stat sb;
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
+ }
+
return ok;
}
bool
tr_torrentFindFile2( const tr_torrent * tor, tr_file_index_t fileNum,
- const char ** base, char ** subpath )
+ const char ** base, char ** subpath, time_t * mtime )
{
char * part = NULL;
const tr_file * file;
if( b == NULL ) {
char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
- if( fileExists( filename ) ) {
+ if( fileExists( filename, mtime ) ) {
b = tor->downloadDir;
s = file->name;
}
if( ( b == NULL ) && ( tor->incompleteDir != NULL ) ) {
char * filename = tr_buildPath( tor->incompleteDir, file->name, NULL );
- if( fileExists( filename ) ) {
+ if( fileExists( filename, mtime ) ) {
b = tor->incompleteDir;
s = file->name;
}
if( ( b == NULL ) && ( tor->incompleteDir != NULL ) ) {
char * filename = tr_buildPath( tor->incompleteDir, part, NULL );
- if( fileExists( filename ) ) {
+ if( fileExists( filename, mtime ) ) {
b = tor->incompleteDir;
s = part;
}
if( b == NULL) {
char * filename = tr_buildPath( tor->downloadDir, part, NULL );
- if( fileExists( filename ) ) {
+ if( fileExists( filename, mtime ) ) {
b = tor->downloadDir;
s = part;
}
char * ret = NULL;
const char * base;
- if( tr_torrentFindFile2( tor, fileNum, &base, &subpath ) )
+ if( tr_torrentFindFile2( tor, fileNum, &base, &subpath, NULL ) )
{
ret = tr_buildPath( base, subpath, NULL );
tr_free( subpath );
dir = tor->downloadDir;
else if( !tr_torrentHasMetadata( tor ) ) /* no files to find */
dir = tor->incompleteDir;
- else if( !tr_torrentFindFile2( tor, 0, &dir, NULL ) )
+ else if( !tr_torrentFindFile2( tor, 0, &dir, NULL, NULL ) )
dir = tor->incompleteDir;
assert( dir != NULL );