Changeset 8910


Ignore:
Timestamp:
Aug 13, 2009, 2:47:56 PM (13 years ago)
Author:
charles
Message:

(trunk libT) fix #2162: .resume file doesn't get saved often enough when its contents change

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r8889 r8910  
    4747#include "version.h"
    4848#include "web.h"
     49
     50enum
     51{
     52    SAVE_INTERVAL_SECS = 120
     53};
     54
    4955
    5056#define dbgmsg( ... ) \
     
    531537}
    532538
     539/***
     540****
     541***/
     542
     543/**
     544 * Periodically save the .resume files of any torrents whose
     545 * status has recently changed.  This prevents loss of metadata
     546 * in the case of a crash, unclean shutdown, clumsy user, etc.
     547 */
     548static void
     549onSaveTimer( int foo UNUSED, short bar UNUSED, void * vsession )
     550{
     551    tr_torrent * tor = NULL;
     552    tr_session * session = vsession;
     553
     554    while(( tor = tr_torrentNext( session, tor )))
     555        tr_torrentSave( tor );
     556
     557    tr_timerAdd( session->saveTimer, SAVE_INTERVAL_SECS, 0 );
     558}
     559
     560/***
     561****
     562***/
     563
    533564static void tr_sessionInitImpl( void * );
    534565static void onAltTimer( int, short, void* );
     
    835866    setAltTimer( session );
    836867
     868    session->saveTimer = tr_new0( struct event, 1 );
     869    evtimer_set( session->saveTimer, onSaveTimer, session );
     870    tr_timerAdd( session->saveTimer, SAVE_INTERVAL_SECS, 0 );
     871
    837872    /* first %s is the application name
    838873       second %s is the version number */
     
    14231458    if( session->isDHTEnabled )
    14241459        tr_dhtUninit( session );
     1460
     1461    evtimer_del( session->saveTimer );
     1462    tr_free( session->saveTimer );
     1463    session->saveTimer = NULL;
    14251464
    14261465    evtimer_del( session->altTimer );
  • trunk/libtransmission/session.h

    r8903 r8910  
    125125
    126126    struct event               * altTimer;
     127    struct event               * saveTimer;
    127128
    128129    /* the size of the output buffer for peer connections */
  • trunk/libtransmission/torrent.c

    r8898 r8910  
    13551355}
    13561356
     1357void
     1358tr_torrentSave( tr_torrent * tor )
     1359{
     1360    assert( tr_isTorrent( tor ) );
     1361
     1362    if( tor->isDirty ) {
     1363        tor->isDirty = FALSE;
     1364        tr_torrentSaveResume( tor );
     1365    }
     1366}
     1367
    13571368static void
    13581369stopTorrent( void * vtor )
     
    13681379    tr_fdTorrentClose( tor->uniqueId );
    13691380
    1370     if( tor->isDirty ) {
    1371         tor->isDirty = 0;
    1372         if( !tor->isDeleting )
    1373             tr_torrentSaveResume( tor );
    1374     }
     1381    if( !tor->isDeleting )
     1382        tr_torrentSave( tor );
    13751383}
    13761384
  • trunk/libtransmission/torrent.h

    r8903 r8910  
    119119void             tr_torrentCheckSeedRatio( tr_torrent * tor );
    120120
     121/** save a torrent's .resume file if it's changed since the last time it was saved */
     122void             tr_torrentSave( tr_torrent * tor );
     123
    121124
    122125
Note: See TracChangeset for help on using the changeset viewer.