mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
(trunk libT) #2716 "magnet torrents not being saved after quit" -- fix regression reported by RolCol @ http://trac.transmissionbt.com/ticket/2716#comment:8
This commit is contained in:
parent
40adcb5491
commit
ef6d874c57
1 changed files with 13 additions and 3 deletions
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <event.h> /* struct evbuffer */
|
#include <event.h> /* struct evbuffer */
|
||||||
|
#include <stdio.h> /* remove() */
|
||||||
|
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "bencode.h"
|
#include "bencode.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "magnet.h"
|
#include "magnet.h"
|
||||||
#include "metainfo.h"
|
#include "metainfo.h"
|
||||||
|
#include "resume.h"
|
||||||
#include "torrent.h"
|
#include "torrent.h"
|
||||||
#include "torrent-magnet.h"
|
#include "torrent-magnet.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -191,18 +193,22 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in
|
||||||
dbgmsg( tor, "err is %d", err );
|
dbgmsg( tor, "err is %d", err );
|
||||||
if(( metainfoParsed = !err ))
|
if(( metainfoParsed = !err ))
|
||||||
{
|
{
|
||||||
/* yay we have bencoded metainfo... merge it into our .torrnet file */
|
/* yay we have bencoded metainfo... merge it into our .torrent file */
|
||||||
tr_benc newMetainfo;
|
tr_benc newMetainfo;
|
||||||
const char * path = tor->info.torrent;
|
char * path = tr_strdup( tor->info.torrent );
|
||||||
|
|
||||||
if( !tr_bencLoadFile( &newMetainfo, TR_FMT_BENC, path ) )
|
if( !tr_bencLoadFile( &newMetainfo, TR_FMT_BENC, path ) )
|
||||||
{
|
{
|
||||||
tr_bool hasInfo;
|
tr_bool hasInfo;
|
||||||
tr_benc * tmp;
|
tr_benc * tmp;
|
||||||
|
|
||||||
|
/* remove any old .torrent and .resume files */
|
||||||
|
remove( path );
|
||||||
|
tr_torrentRemoveResume( tor );
|
||||||
|
|
||||||
dbgmsg( tor, "Saving completed metadata to \"%s\"", path );
|
dbgmsg( tor, "Saving completed metadata to \"%s\"", path );
|
||||||
assert( !tr_bencDictFindDict( &newMetainfo, "info", &tmp ) );
|
assert( !tr_bencDictFindDict( &newMetainfo, "info", &tmp ) );
|
||||||
tr_bencMergeDicts( tr_bencDictAddDict( &newMetainfo, "info", 0 ), &infoDict );
|
tr_bencMergeDicts( tr_bencDictAddDict( &newMetainfo, "info", 0 ), &infoDict );
|
||||||
tr_bencToFile( &newMetainfo, TR_FMT_BENC, path );
|
|
||||||
|
|
||||||
success = tr_metainfoParse( tor->session, &newMetainfo, &tor->info,
|
success = tr_metainfoParse( tor->session, &newMetainfo, &tor->info,
|
||||||
&hasInfo, &tor->infoDictOffset, &tor->infoDictLength );
|
&hasInfo, &tor->infoDictOffset, &tor->infoDictLength );
|
||||||
|
@ -210,6 +216,9 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in
|
||||||
assert( hasInfo );
|
assert( hasInfo );
|
||||||
assert( success );
|
assert( success );
|
||||||
|
|
||||||
|
/* save the new .torrent file */
|
||||||
|
tr_bencToFile( &newMetainfo, TR_FMT_BENC, tor->info.torrent );
|
||||||
|
tr_sessionSetTorrentFile( tor->session, tor->info.hashString, tor->info.torrent );
|
||||||
tr_torrentGotNewInfoDict( tor );
|
tr_torrentGotNewInfoDict( tor );
|
||||||
tr_torrentSetDirty( tor );
|
tr_torrentSetDirty( tor );
|
||||||
|
|
||||||
|
@ -217,6 +226,7 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_bencFree( &infoDict );
|
tr_bencFree( &infoDict );
|
||||||
|
tr_free( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue