diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 11bfdda09..de5cfa64d 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -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 ); + } } } diff --git a/libtransmission/utils.c b/libtransmission/utils.c index fec852ac8..11495f10e 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -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 ); diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 7a367573e..bc509c898 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -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