1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-23 22:50:41 +00:00

simplify tr_torrentParse() based on BWM's feedback

This commit is contained in:
Charles Kerr 2007-06-27 23:22:09 +00:00
parent 71470aa852
commit 63fce9cf06
2 changed files with 23 additions and 37 deletions

View file

@ -269,8 +269,8 @@ infoCanAdd( const tr_handle_t * h,
if( hashExists( h, info->hash ) )
return TR_EDUPLICATE;
if( pathIsInUse( h, destination, info->name ) )
return TR_ERROR_IO_DUP_DOWNLOAD;
if( destination && pathIsInUse( h, destination, info->name ) )
return TR_EDUPLICATE;
return TR_OK;
}
@ -279,8 +279,7 @@ int
tr_torrentParse( const tr_handle_t * h,
const char * path,
const char * destination,
tr_info_t * setme_info,
int * setme_canAdd )
tr_info_t * setme_info )
{
int ret;
tr_info_t tmp;
@ -290,8 +289,8 @@ tr_torrentParse( const tr_handle_t * h,
ret = tr_metainfoParseFile( setme_info, h->tag, path, FALSE );
if( setme_canAdd )
*setme_canAdd = ret ? ret : infoCanAdd( h, destination, setme_info );
if( ret == TR_OK )
ret = infoCanAdd( h, destination, setme_info );
return ret;
}
@ -304,13 +303,10 @@ tr_torrentInit( tr_handle_t * h,
int * error )
{
int val;
int err = 0;
tr_torrent_t * tor = NULL;
if(( val = tr_torrentParse( h, destination, path, NULL, &err )))
if(( val = tr_torrentParse( h, destination, path, NULL )))
*error = val;
else if( err )
*error = err;
else if(!(( tor = tr_new0( tr_torrent_t, 1 ))))
*error = TR_EOTHER;
else {
@ -325,8 +321,7 @@ static int
tr_torrentParseHash( const tr_handle_t * h,
const char * hashStr,
const char * destination,
tr_info_t * setme_info,
int * setme_canAdd )
tr_info_t * setme_info )
{
int ret;
tr_info_t tmp;
@ -336,8 +331,8 @@ tr_torrentParseHash( const tr_handle_t * h,
ret = tr_metainfoParseHash( setme_info, h->tag, hashStr );
if( setme_canAdd )
*setme_canAdd = ret ? ret : infoCanAdd( h, destination, setme_info );
if( ret == TR_OK )
ret = infoCanAdd( h, destination, setme_info );
return ret;
}
@ -351,13 +346,10 @@ tr_torrentInitSaved( tr_handle_t * h,
int * error )
{
int val;
int err = 0;
tr_torrent_t * tor = NULL;
if(( val = tr_torrentParseHash( h, hashStr, destination, NULL, &err )))
if(( val = tr_torrentParseHash( h, hashStr, destination, NULL )))
*error = val;
else if( err )
*error = err;
else if(!(( tor = tr_new0( tr_torrent_t, 1 ))))
*error = TR_EOTHER;
else {
@ -373,8 +365,7 @@ tr_torrentParseData( const tr_handle_t * h,
const uint8_t * data,
size_t size,
const char * destination,
tr_info_t * setme_info,
int * setme_canAdd )
tr_info_t * setme_info )
{
int ret;
tr_info_t tmp;
@ -384,8 +375,8 @@ tr_torrentParseData( const tr_handle_t * h,
ret = tr_metainfoParseData( setme_info, h->tag, data, size, FALSE );
if( setme_canAdd )
*setme_canAdd = ret ? ret : infoCanAdd( h, destination, setme_info );
if( ret == TR_OK )
ret = infoCanAdd( h, destination, setme_info );
return ret;
}
@ -399,13 +390,10 @@ tr_torrentInitData( tr_handle_t * h,
int * error )
{
int val;
int err = 0;
tr_torrent_t * tor = NULL;
if(( val = tr_torrentParseData( h, data, size, destination, NULL, &err ) ))
if(( val = tr_torrentParseData( h, data, size, destination, NULL )))
*error = val;
else if( err )
*error = err;
else if(!(( tor = tr_new0( tr_torrent_t, 1 ))))
*error = TR_EOTHER;
else {

View file

@ -274,23 +274,21 @@ typedef struct tr_info_s tr_info_t;
/**
* Parses the specified metainfo file.
*
* Returns TR_OK or TR_INVALID based on whether or not the
* metainfo file is successfully parsed.
* Returns TR_OK if it parsed and can be added to Transmission.
* Returns TR_INVALID if it couldn't be parsed.
* Returns TR_EDUPLICATE if it parsed but can't be added.
*
* If parsing succeeded and "setme_info" is non-NULL,
* it will be populated with the file's information.
* "destination" can be NULL if you don't need to know whether
* or not the torrent can be added.
*
* If "setme_canAdd" is non-NULL, it will be set to TR_OK,
* TR_EDUPLICATE, TR_ERROR_IO_DUP_DOWNLOAD, or TR_EINVALID.
*
* "destination" is used for the canAdd tests, so it can
* be NULL if "setme_canAdd" is too.
" "setme_info" can be NULL if you don't need the information.
* If the metainfo can be parsed and setme_info is non-NULL,
* it will be filled with the metadata's info.
*/
int tr_torrentParse( const tr_handle_t * handle,
const char * metainfo_filename,
const char * destination,
tr_info_t * setme_info,
int * setme_canAdd );
tr_info_t * setme_info );
/***********************************************************************
* tr_torrentInitData