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:
parent
cf29f57b5a
commit
6af5b7691e
1 changed files with 14 additions and 10 deletions
|
@ -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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue