Changeset 10191 for trunk/libtransmission/verify.c
- Timestamp:
- Feb 13, 2010, 5:46:31 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/verify.c
r10187 r10191 48 48 /* #define STOPWATCH */ 49 49 50 #ifndef HAVE_VALLOC 51 #define valloc malloc 52 #endif 53 50 54 static tr_bool 51 55 verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) … … 60 64 uint32_t pieceBytesRead = 0; 61 65 tr_file_index_t fileIndex = 0; 66 tr_file_index_t prevFileIndex = !fileIndex; 62 67 tr_piece_index_t pieceIndex = 0; 63 uint8_t * buffer = NULL;64 int64_t buflen = 0;68 const int64_t buflen = 4096; 69 uint8_t * buffer = valloc( buflen ); 65 70 const time_t begin = tr_time( ); 66 71 time_t end; … … 73 78 int64_t leftInFile; 74 79 int64_t bytesThisPass; 75 ssize_t numRead;76 80 const tr_file * file = &tor->info.files[fileIndex]; 77 81 … … 84 88 85 89 /* if we're starting a new file... */ 86 if( !filePos && (fd<0) )90 if( !filePos && (fd<0) && (fileIndex!=prevFileIndex) ) 87 91 { 88 92 char * filename = tr_torrentFindFile( tor, fileIndex ); 89 93 fd = filename == NULL ? -1 : tr_open_file_for_scanning( filename ); 90 94 /* fprintf( stderr, "opening file #%d (%s) -- %d\n", fileIndex, filename, fd ); */ 91 if( ( fd >= 0 ) && ( buffer == NULL ) )92 {93 struct stat st;94 buflen = fstat( fd, &st ) ? 4096 : st.st_blksize;95 #ifdef HAVE_VALLOC96 buffer = valloc( buflen );97 #else98 buffer = malloc( buflen );99 #endif100 }101 95 tr_free( filename ); 96 prevFileIndex = fileIndex; 102 97 } 103 98 … … 110 105 111 106 /* read a bit */ 112 numRead = tr_pread( fd, buffer, bytesThisPass, filePos ); 113 if( numRead == bytesThisPass ) 114 SHA1_Update( &sha, buffer, numRead ); 115 if( numRead > 0 ) { 116 pieceBytesRead += numRead; 107 if( fd >= 0 ) { 108 const ssize_t numRead = tr_pread( fd, buffer, bytesThisPass, filePos ); 109 if( numRead == bytesThisPass ) 110 SHA1_Update( &sha, buffer, numRead ); 111 if( numRead > 0 ) { 112 pieceBytesRead += numRead; 117 113 #if defined HAVE_POSIX_FADVISE && defined POSIX_FADV_DONTNEED 118 posix_fadvise( fd, filePos, bytesThisPass, POSIX_FADV_DONTNEED ); 119 #endif 114 posix_fadvise( fd, filePos, bytesThisPass, POSIX_FADV_DONTNEED ); 115 #endif 116 } 120 117 } 121 118
Note: See TracChangeset
for help on using the changeset viewer.