mirror of
https://github.com/transmission/transmission
synced 2025-03-10 14:13:23 +00:00
(trunk libT) close open files immediately after they're done downloading
This commit is contained in:
parent
014015d1ef
commit
a13e0755f0
3 changed files with 45 additions and 4 deletions
|
@ -315,3 +315,23 @@ tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t piece )
|
||||||
{
|
{
|
||||||
return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
|
return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr_bool
|
||||||
|
tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex )
|
||||||
|
{
|
||||||
|
tr_block_index_t block;
|
||||||
|
|
||||||
|
const tr_torrent * tor = cp->tor;
|
||||||
|
const tr_file * file = &tor->info.files[fileIndex];
|
||||||
|
const tr_block_index_t firstBlock = file->offset / tor->blockSize;
|
||||||
|
const tr_block_index_t lastBlock = ( file->offset + file->length - 1 ) / tor->blockSize;
|
||||||
|
|
||||||
|
assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece );
|
||||||
|
assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece );
|
||||||
|
|
||||||
|
for( block=firstBlock; block<=lastBlock; ++block )
|
||||||
|
if( !tr_cpBlockIsComplete( cp, block ) )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -128,11 +128,13 @@ void tr_cpPieceAdd( tr_completion * completion,
|
||||||
void tr_cpPieceRem( tr_completion * completion,
|
void tr_cpPieceRem( tr_completion * completion,
|
||||||
tr_piece_index_t piece );
|
tr_piece_index_t piece );
|
||||||
|
|
||||||
|
tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*** Blocks
|
*** Blocks
|
||||||
**/
|
**/
|
||||||
|
|
||||||
static TR_INLINE int tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {
|
static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {
|
||||||
return tr_bitfieldHas( &cp->blockBitfield, block );
|
return tr_bitfieldHas( &cp->blockBitfield, block );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "clients.h"
|
#include "clients.h"
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
#include "fdlimit.h"
|
||||||
#include "handshake.h"
|
#include "handshake.h"
|
||||||
#include "inout.h" /* tr_ioTestPiece */
|
#include "inout.h" /* tr_ioTestPiece */
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
@ -1087,14 +1088,32 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
|
||||||
tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p, ok );
|
tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p, ok );
|
||||||
|
|
||||||
if( !ok )
|
if( !ok )
|
||||||
|
{
|
||||||
gotBadPiece( t, p );
|
gotBadPiece( t, p );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int peerCount = tr_ptrArraySize( &t->peers );
|
int peerCount;
|
||||||
tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
|
tr_peer ** peers;
|
||||||
|
tr_file_index_t fileIndex;
|
||||||
|
|
||||||
|
peerCount = tr_ptrArraySize( &t->peers );
|
||||||
|
peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
|
||||||
for( i=0; i<peerCount; ++i )
|
for( i=0; i<peerCount; ++i )
|
||||||
tr_peerMsgsHave( peers[i]->msgs, p );
|
tr_peerMsgsHave( peers[i]->msgs, p );
|
||||||
|
|
||||||
|
for( fileIndex=0; fileIndex<tor->info.fileCount; ++fileIndex )
|
||||||
|
{
|
||||||
|
const tr_file * file = &tor->info.files[fileIndex];
|
||||||
|
if( ( file->firstPiece <= p ) && ( p <= file->lastPiece ) && tr_cpFileIsComplete( &tor->completion, fileIndex ) )
|
||||||
|
{
|
||||||
|
char * path = tr_buildPath( tor->downloadDir, file->name, NULL );
|
||||||
|
tordbg( t, "closing recently-completed file \"%s\"", path );
|
||||||
|
tr_fdFileClose( path );
|
||||||
|
tr_free( path );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_torrentRecheckCompleteness( tor );
|
tr_torrentRecheckCompleteness( tor );
|
||||||
|
|
Loading…
Add table
Reference in a new issue