1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-29 11:06:23 +00:00

(trunk libT) make tr_torrentFileCompleted() safe for older torrents that were incomplete before the ".part" feature was added

This commit is contained in:
Charles Kerr 2009-10-19 13:15:46 +00:00
parent cf29f57b5a
commit 6af5b7691e

View file

@ -2518,20 +2518,24 @@ tr_torrentCheckSeedRatio( tr_torrent * tor )
void void
tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum ) tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum )
{ {
char * oldpath = tr_torrentFindFile( tor, fileNum ); char * oldpath;
char * newpath = tr_strdup( oldpath );
char * pch = strrchr( newpath, '.' );
assert( !strcmp( pch, ".part" ) );
*pch = '\0';
/* close the file so that we can reopen in read-only mode as needed */ /* close the file so that we can reopen in read-only mode as needed */
tr_fdFileClose( tor, fileNum ); tr_fdFileClose( tor, fileNum );
/* strip the trailing ".part" from the filename */ /* if the torrent's file ends in ".part" to show that it was incomplete,
if( rename( oldpath, newpath ) ) * strip that suffix */
tr_torerr( tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) ); oldpath = tr_torrentFindFile( tor, fileNum );
if( oldpath != NULL ) {
tr_free( newpath ); char * newpath = tr_strdup( oldpath );
char * pch = strrchr( newpath, '.' );
if(( pch != NULL ) && !strcmp( pch, ".part" )) {
*pch = '\0';
if( rename( oldpath, newpath ) )
tr_torerr( tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) );
}
tr_free( newpath );
}
tr_free( oldpath ); tr_free( oldpath );
} }