1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-09 13:50:00 +00:00

Add an option for saving a torrent's destination path in its file. This can be overridden by clients with the `destination' argument in tr_torrentInit*()

This commit is contained in:
Charles Kerr 2007-10-12 19:45:51 +00:00
parent 1e9cb5a21a
commit ff36475fad
3 changed files with 60 additions and 4 deletions

View file

@ -103,7 +103,10 @@ enum
FR_ID_CORRUPT = 10,
/* IPs and ports of connectable peers */
FR_ID_PEERS = 11
FR_ID_PEERS = 11,
/* destination of the torrent: zero-terminated string */
FR_ID_DESTINATION = 12
};
@ -282,6 +285,13 @@ tr_fastResumeSave( const tr_torrent * tor )
fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file );
}
if( TRUE ) /* FR_ID_DESTINATION */
{
const char * d = tor->destination ? tor->destination : "";
const int byteCount = strlen( d ) + 1;
fastResumeWriteData( FR_ID_DESTINATION, d, 1, byteCount, file );
}
/* Write download and upload totals */
total = tor->downloadedCur + tor->downloadedPrev;
@ -309,6 +319,31 @@ tr_fastResumeSave( const tr_torrent * tor )
tr_dbg( "Resume file '%s' written", path );
}
static int
loadDestination( tr_torrent * tor, FILE * fp )
{
int pathlen = 0;
char path[MAX_PATH_LENGTH];
for( ;; ) {
const int ch = fgetc( fp );
if( ch==EOF ) /* end of file */
return TR_ERROR_IO_OTHER;
if( ch=='\0' ) /* end of string */
break;
path[pathlen++] = (char) ch;
}
path[pathlen] = '\0';
if( pathlen ) {
tr_free( tor->destination );
tor->destination = tr_strdup( path );
}
return TR_OK;
}
static int
loadSpeeds( tr_torrent * tor, FILE * file )
{
@ -580,6 +615,21 @@ fastResumeLoadImpl ( tr_torrent * tor,
}
break;
case FR_ID_DESTINATION:
{
const int rret = loadDestination( tor, file );
if( rret && ( feof(file) || ferror(file) ) )
{
fclose( file );
return ret;
}
ret |= TR_FR_DESTINATION;;
continue;
}
break;
case FR_ID_RUN:
{
char ch;

View file

@ -36,7 +36,8 @@ enum
TR_FR_PROGRESS = (1<<4),
TR_FR_PRIORITY = (1<<5),
TR_FR_SPEEDLIMIT = (1<<6),
TR_FR_RUN = (1<<7)
TR_FR_RUN = (1<<7),
TR_FR_DESTINATION = (1<<8),
};
/**

View file

@ -269,8 +269,6 @@ torrentRealInit( tr_handle * h,
tr_globalLock( h );
tor->destination = tr_strdup( destination );
tor->handle = h;
tor->pexDisabled = 0;
@ -342,6 +340,13 @@ torrentRealInit( tr_handle * h,
uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount );
loaded = tr_fastResumeLoad( tor, uncheckedPieces );
/* a path passed in by the user overrides
the one loaded by fastresume... */
if( destination && *destination ) {
tr_free( tor->destination );
tor->destination = tr_strdup( destination );
}
/* the `paused' flag has highest precedence...
after that, the fastresume setting is used...
if that's not found, default to RUNNING */