mirror of
https://github.com/transmission/transmission
synced 2025-02-15 19:04:45 +00:00
(trunk libT) #3297 "tr_makemeta() should use tr_open_file_for_scanning()" -- implemented in trunk for 2.10
This commit is contained in:
parent
d3c4c1ec16
commit
82f0ec7413
1 changed files with 11 additions and 10 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "crypto.h" /* tr_sha1 */
|
#include "crypto.h" /* tr_sha1 */
|
||||||
|
#include "fdlimit.h" /* tr_open_file_for_scanning() */
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "bencode.h"
|
#include "bencode.h"
|
||||||
#include "makemeta.h"
|
#include "makemeta.h"
|
||||||
|
@ -203,7 +204,7 @@ getHashInfo( tr_metainfo_builder * b )
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
uint64_t totalRemain;
|
uint64_t totalRemain;
|
||||||
uint64_t off = 0;
|
uint64_t off = 0;
|
||||||
FILE * fp;
|
int fd;
|
||||||
|
|
||||||
if( !b->totalSize )
|
if( !b->totalSize )
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -211,8 +212,8 @@ getHashInfo( tr_metainfo_builder * b )
|
||||||
buf = tr_valloc( b->pieceSize );
|
buf = tr_valloc( b->pieceSize );
|
||||||
b->pieceIndex = 0;
|
b->pieceIndex = 0;
|
||||||
totalRemain = b->totalSize;
|
totalRemain = b->totalSize;
|
||||||
fp = fopen( b->files[fileIndex].filename, "rb" );
|
fd = tr_open_file_for_scanning( b->files[fileIndex].filename );
|
||||||
if( !fp )
|
if( fd < 0 )
|
||||||
{
|
{
|
||||||
b->my_errno = errno;
|
b->my_errno = errno;
|
||||||
tr_strlcpy( b->errfile,
|
tr_strlcpy( b->errfile,
|
||||||
|
@ -236,19 +237,19 @@ getHashInfo( tr_metainfo_builder * b )
|
||||||
{
|
{
|
||||||
const uint64_t n_this_pass =
|
const uint64_t n_this_pass =
|
||||||
MIN( ( b->files[fileIndex].size - off ), pieceRemain );
|
MIN( ( b->files[fileIndex].size - off ), pieceRemain );
|
||||||
fread( bufptr, 1, n_this_pass, fp );
|
read( fd, bufptr, n_this_pass );
|
||||||
bufptr += n_this_pass;
|
bufptr += n_this_pass;
|
||||||
off += n_this_pass;
|
off += n_this_pass;
|
||||||
pieceRemain -= n_this_pass;
|
pieceRemain -= n_this_pass;
|
||||||
if( off == b->files[fileIndex].size )
|
if( off == b->files[fileIndex].size )
|
||||||
{
|
{
|
||||||
off = 0;
|
off = 0;
|
||||||
fclose( fp );
|
tr_close_file( fd );
|
||||||
fp = NULL;
|
fd = -1;
|
||||||
if( ++fileIndex < b->fileCount )
|
if( ++fileIndex < b->fileCount )
|
||||||
{
|
{
|
||||||
fp = fopen( b->files[fileIndex].filename, "rb" );
|
fd = tr_open_file_for_scanning( b->files[fileIndex].filename );
|
||||||
if( !fp )
|
if( fd < 0 )
|
||||||
{
|
{
|
||||||
b->my_errno = errno;
|
b->my_errno = errno;
|
||||||
tr_strlcpy( b->errfile,
|
tr_strlcpy( b->errfile,
|
||||||
|
@ -282,8 +283,8 @@ getHashInfo( tr_metainfo_builder * b )
|
||||||
|| ( walk - ret == (int)( SHA_DIGEST_LENGTH * b->pieceCount ) ) );
|
|| ( walk - ret == (int)( SHA_DIGEST_LENGTH * b->pieceCount ) ) );
|
||||||
assert( b->abortFlag || !totalRemain );
|
assert( b->abortFlag || !totalRemain );
|
||||||
|
|
||||||
if( fp )
|
if( fd >= 0 )
|
||||||
fclose( fp );
|
tr_close_file( fd );
|
||||||
|
|
||||||
tr_free( buf );
|
tr_free( buf );
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue