Ticket #3297: makemeta.diff
File makemeta.diff, 2.1 KB (added by charles, 12 years ago) |
---|
-
libtransmission/makemeta.c
23 23 24 24 #include "transmission.h" 25 25 #include "crypto.h" /* tr_sha1 */ 26 #include "fdlimit.h" /* tr_open_file_for_scanning() */ 26 27 #include "session.h" 27 28 #include "bencode.h" 28 29 #include "makemeta.h" … … 203 204 uint8_t *buf; 204 205 uint64_t totalRemain; 205 206 uint64_t off = 0; 206 FILE * fp;207 int fd; 207 208 208 209 if( !b->totalSize ) 209 210 return ret; … … 211 212 buf = tr_valloc( b->pieceSize ); 212 213 b->pieceIndex = 0; 213 214 totalRemain = b->totalSize; 214 f p = fopen( b->files[fileIndex].filename, "rb");215 if( !fp)215 fd = tr_open_file_for_scanning( b->files[fileIndex].filename ); 216 if( fd < 0 ) 216 217 { 217 218 b->my_errno = errno; 218 219 tr_strlcpy( b->errfile, … … 236 237 { 237 238 const uint64_t n_this_pass = 238 239 MIN( ( b->files[fileIndex].size - off ), pieceRemain ); 239 fread( bufptr, 1, n_this_pass, fp);240 read( fd, bufptr, n_this_pass ); 240 241 bufptr += n_this_pass; 241 242 off += n_this_pass; 242 243 pieceRemain -= n_this_pass; 243 244 if( off == b->files[fileIndex].size ) 244 245 { 245 246 off = 0; 246 fclose( fp);247 f p = NULL;247 tr_close_file( fd ); 248 fd = -1; 248 249 if( ++fileIndex < b->fileCount ) 249 250 { 250 f p = fopen( b->files[fileIndex].filename, "rb");251 if( !fp)251 fd = tr_open_file_for_scanning( b->files[fileIndex].filename ); 252 if( fd < 0 ) 252 253 { 253 254 b->my_errno = errno; 254 255 tr_strlcpy( b->errfile, … … 282 283 || ( walk - ret == (int)( SHA_DIGEST_LENGTH * b->pieceCount ) ) ); 283 284 assert( b->abortFlag || !totalRemain ); 284 285 285 if( f p)286 fclose( fp);286 if( fd >= 0 ) 287 tr_close_file( fd ); 287 288 288 289 tr_free( buf ); 289 290 return ret;