Skip to content

Commit

Permalink
patch for skip hash check
Browse files Browse the repository at this point in the history
  • Loading branch information
shengjia committed Oct 27, 2016
1 parent f6a7f1f commit 56e327d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions libtransmission/rpcimpl.c
Expand Up @@ -386,6 +386,7 @@ torrentReannounce (tr_session * session,

assert (idle_data == NULL);

skiphash();
torrents = getTorrents (session, args_in, &torrentCount);
for (i=0; i<torrentCount; ++i)
{
Expand Down
15 changes: 12 additions & 3 deletions libtransmission/verify.c
Expand Up @@ -39,6 +39,11 @@ enum
MSEC_TO_SLEEP_PER_SECOND_DURING_VERIFY = 100
};

static bool skiphashcheck=false;
void skiphash(){
skiphashcheck=true;
}

static bool
verifyTorrent (tr_torrent * tor, bool * stopFlag)
{
Expand Down Expand Up @@ -73,7 +78,7 @@ verifyTorrent (tr_torrent * tor, bool * stopFlag)
hadPiece = tr_torrentPieceIsComplete (tor, pieceIndex);

/* if we're starting a new file... */
if (filePos == 0 && fd == TR_BAD_SYS_FILE && fileIndex != prevFileIndex)
if (!skiphashcheck && filePos == 0 && fd == TR_BAD_SYS_FILE && fileIndex != prevFileIndex)
{
char * filename = tr_torrentFindFile (tor, fileIndex);
fd = filename == NULL ? TR_BAD_SYS_FILE : tr_sys_file_open (filename,
Expand All @@ -92,7 +97,7 @@ verifyTorrent (tr_torrent * tor, bool * stopFlag)
if (fd != TR_BAD_SYS_FILE)
{
uint64_t numRead;
if (tr_sys_file_read_at (fd, buffer, bytesThisPass, filePos, &numRead, NULL) && numRead > 0)
if (!skiphashcheck && tr_sys_file_read_at (fd, buffer, bytesThisPass, filePos, &numRead, NULL) && numRead > 0)
{
bytesThisPass = numRead;
tr_sha1_update (sha, buffer, bytesThisPass);
Expand All @@ -116,7 +121,7 @@ verifyTorrent (tr_torrent * tor, bool * stopFlag)
uint8_t hash[SHA_DIGEST_LENGTH];

tr_sha1_final (sha, hash);
hasPiece = !memcmp (hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH);
hasPiece = skiphashcheck || !memcmp (hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH);

if (hasPiece || hadPiece)
{
Expand Down Expand Up @@ -154,6 +159,10 @@ verifyTorrent (tr_torrent * tor, bool * stopFlag)
}
}

if(skiphashcheck){
skiphashcheck=false;
tr_logAddTorInfo (tor, "%s", _("skip hash check"));
}
/* cleanup */
if (fd != TR_BAD_SYS_FILE)
tr_sys_file_close (fd, NULL);
Expand Down

0 comments on commit 56e327d

Please sign in to comment.