Changeset 11506 for trunk/libtransmission/resume.c
- Timestamp:
- Dec 9, 2010, 8:43:23 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/resume.c
r11455 r11506 61 61 #define KEY_IDLELIMIT_MODE "idle-mode" 62 62 63 #define KEY_PROGRESS_ MTIMES "mtimes"63 #define KEY_PROGRESS_CHECKTIME "time-checked" 64 64 #define KEY_PROGRESS_BITFIELD "bitfield" 65 65 #define KEY_PROGRESS_HAVE "have" … … 416 416 { 417 417 size_t i, n; 418 time_t * mtimes;419 418 tr_benc * p; 420 419 tr_benc * m; … … 424 423 tr_bencInitDict( p, 2 ); 425 424 426 /* add the mtimes */ 427 mtimes = tr_torrentGetMTimes( tor, &n ); 428 m = tr_bencDictAddList( p, KEY_PROGRESS_MTIMES, n ); 429 for( i = 0; i < n; ++i ) 430 { 431 if( !tr_torrentIsFileChecked( tor, i ) ) 432 mtimes[i] = ~(time_t)0; /* force a recheck */ 433 tr_bencListAddInt( m, mtimes[i] ); 434 } 425 /* add each piece's timeChecked */ 426 n = tor->info.pieceCount; 427 m = tr_bencDictAddList( p, KEY_PROGRESS_CHECKTIME, n ); 428 for( i=0; i<n; ++i ) 429 tr_bencListAddInt( m, tor->info.pieces[i].timeChecked ); 435 430 436 431 /* add the progress */ … … 440 435 tr_bencDictAddRaw( p, KEY_PROGRESS_BITFIELD, 441 436 bitfield->bits, bitfield->byteCount ); 442 443 /* cleanup */444 tr_free( mtimes );445 437 } 446 438 … … 449 441 tr_torrent * tor ) 450 442 { 443 size_t i, n; 451 444 uint64_t ret = 0; 452 445 tr_benc * p; 446 447 for( i=0, n=tor->info.pieceCount; i<n; ++i ) 448 tor->info.pieces[i].timeChecked = 0; 453 449 454 450 if( tr_bencDictFindDict( dict, KEY_PROGRESS, &p ) ) … … 459 455 size_t rawlen; 460 456 tr_benc * m; 461 size_t n; 462 time_t * curMTimes = tr_torrentGetMTimes( tor, &n ); 463 464 if( tr_bencDictFindList( p, KEY_PROGRESS_MTIMES, &m ) 465 && ( n == tor->info.fileCount ) 466 && ( n == tr_bencListSize( m ) ) ) 467 { 468 size_t i; 469 for( i = 0; i < n; ++i ) 470 { 471 int64_t tmp; 472 if( !tr_bencGetInt( tr_bencListChild( m, i ), &tmp ) ) 473 { 474 tr_tordbg( 475 tor, 476 "File #%zu needs to be verified - couldn't find benc entry", 477 i ); 478 tr_torrentSetFileChecked( tor, i, FALSE ); 479 } 480 else 481 { 482 const time_t t = (time_t) tmp; 483 if( t == curMTimes[i] ) 484 tr_torrentSetFileChecked( tor, i, TRUE ); 485 else 486 { 487 tr_tordbg( 488 tor, 489 "File #%zu needs to be verified - times %lu and %lu don't match", 490 i, t, curMTimes[i] ); 491 tr_torrentSetFileChecked( tor, i, FALSE ); 492 } 493 } 494 } 495 } 496 else 497 { 498 tr_torrentUncheck( tor ); 499 tr_tordbg( 500 tor, "Torrent needs to be verified - unable to find mtimes" ); 501 } 457 int64_t timeChecked; 458 459 /* load in the timestamp of when we last checked each piece */ 460 if( tr_bencDictFindList( p, KEY_PROGRESS_CHECKTIME, &m ) ) 461 for( i=0, n=tor->info.pieceCount; i<n; ++i ) 462 if( tr_bencGetInt( tr_bencListChild( m, i ), &timeChecked ) ) 463 tor->info.pieces[i].timeChecked = (time_t)timeChecked; 502 464 503 465 err = NULL; … … 519 481 } 520 482 else err = "Couldn't find 'have' or 'bitfield'"; 483 521 484 if( err != NULL ) 522 {523 tr_torrentUncheck( tor );524 485 tr_tordbg( tor, "Torrent needs to be verified - %s", err ); 525 } 526 527 tr_free( curMTimes ); 486 528 487 ret = TR_FR_PROGRESS; 529 488 }
Note: See TracChangeset
for help on using the changeset viewer.