(trunk libT) #2531: when the user moves a torrent from one location to another, we don't need to reverify if the files are just rename()d

This commit is contained in:
Charles Kerr 2009-10-27 23:00:34 +00:00
parent 9a631b666d
commit 22e3f1175a
3 changed files with 22 additions and 12 deletions

View File

@ -2418,17 +2418,18 @@ setLocation( void * vdata )
if( do_move )
{
tr_bool renamed = FALSE;
errno = 0;
tr_torinf( tor, "moving \"%s\" to \"%s\"", oldpath, newpath );
if( rename( oldpath, newpath ) )
if( tr_moveFile( oldpath, newpath, &renamed ) )
{
err = TRUE;
tr_torerr( tor, "error moving \"%s\" to \"%s\": %s",
oldpath, newpath, tr_strerror( errno ) );
}
else if( !renamed )
{
verify_needed = TRUE;
if( tr_moveFile( oldpath, newpath ) )
{
err = TRUE;
tr_torerr( tor, "error moving \"%s\" to \"%s\": %s",
oldpath, newpath, tr_strerror( errno ) );
}
}
}
@ -2454,6 +2455,10 @@ setLocation( void * vdata )
tr_torrentSetDownloadDir( tor, location );
if( verify_needed )
tr_torrentVerify( tor );
else if( tor->startAfterVerify ) {
tor->startAfterVerify = FALSE;
tr_torrentStart( tor );
}
}
}

View File

@ -1355,7 +1355,7 @@ tr_strratio( char * buf, size_t buflen, double ratio, const char * infinity )
***/
int
tr_moveFile( const char * oldpath, const char * newpath )
tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed )
{
int in;
int out;
@ -1385,9 +1385,14 @@ tr_moveFile( const char * oldpath, const char * newpath )
return i;
}
/* they might be on the same filesystem... */
if( !rename( oldpath, newpath ) )
return 0;
/* they might be on the same filesystem... */
{
const int i = rename( oldpath, newpath );
if( renamed != NULL )
*renamed = i == 0;
if( !i )
return 0;
}
/* copy the file */
in = tr_open_file_for_scanning( oldpath );

View File

@ -419,7 +419,7 @@ struct tm * tr_localtime_r( const time_t *_clock, struct tm *_result );
/** on success, return 0. on failure, return -1 and set errno */
int tr_moveFile( const char * oldpath, const char * newpath );
int tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed );
#ifdef __cplusplus