Ticket #3675: delete-on-remove.diff

File delete-on-remove.diff, 6.3 KB (added by charles, 11 years ago)
  • libtransmission/rpcimpl.c

     
    253253    {
    254254        tr_torrent * tor = torrents[i];
    255255        const tr_rpc_callback_status status = notify( session, TR_RPC_TORRENT_REMOVING, tor );
    256         tr_bool deleteFlag;
    257         if( tr_bencDictFindBool( args_in, "delete-local-data", &deleteFlag ) && deleteFlag )
    258             tr_torrentDeleteLocalData( tor, NULL );
    259256        if( !( status & TR_RPC_NOREMOVE ) )
    260             tr_torrentRemove( tor );
     257        {
     258            tr_bool deleteFlag = FALSE;
     259            tr_bencDictFindBool( args_in, "delete-local-data", &deleteFlag );
     260            tr_torrentRemove( tor, deleteFlag, NULL );
     261        }
    261262    }
    262263
    263264    tr_free( torrents );
  • libtransmission/transmission.h

     
    10311031           Running torrents are stopped first.  */
    10321032void tr_torrentFree( tr_torrent * torrent );
    10331033
     1034typedef int tr_fileFunc( const char * filename );
     1035
    10341036/** @brief Removes our .torrent and .resume files for
    10351037           this torrent, then calls tr_torrentFree(). */
    1036 void tr_torrentRemove( tr_torrent * torrent );
     1038void tr_torrentRemove( tr_torrent  * torrent,
     1039                       tr_bool       removeLocalData,
     1040                       tr_fileFunc   removeFunc );
    10371041
    10381042/** @brief Start a torrent */
    10391043void tr_torrentStart( tr_torrent * torrent );
     
    10611065                            double      * setme_progress,
    10621066                            int         * setme_state );
    10631067
    1064 typedef int tr_fileFunc( const char * filename );
    1065 
    10661068/**
    10671069 * @brief Deletes the torrent's local data.
    10681070 * @param torrent
  • libtransmission/torrent.c

     
    17501750    }
    17511751}
    17521752
     1753struct remove_data
     1754{
     1755    tr_torrent   * tor;
     1756    tr_bool        deleteFlag;
     1757    tr_fileFunc  * deleteFunc;
     1758};
     1759
     1760static void
     1761removeTorrent( void * vdata )
     1762{
     1763    struct remove_data * data = vdata;
     1764
     1765    if( data->deleteFlag )
     1766        tr_torrentDeleteLocalData( data->tor, data->deleteFunc );
     1767
     1768    tr_torrentClearCompletenessCallback( data->tor );
     1769    closeTorrent( data->tor );
     1770    tr_free( data );
     1771}
     1772
    17531773void
    1754 tr_torrentRemove( tr_torrent * tor )
     1774tr_torrentRemove( tr_torrent   * tor,
     1775                  tr_bool        deleteFlag,
     1776                  tr_fileFunc    deleteFunc )
    17551777{
     1778    struct remove_data * data;
     1779
    17561780    assert( tr_isTorrent( tor ) );
     1781    tor->isDeleting = 1;
    17571782
    1758     tor->isDeleting = 1;
    1759     tr_torrentFree( tor );
     1783    data = tr_new0( struct remove_data, 1 );
     1784    data->tor = tor;
     1785    data->deleteFlag = deleteFlag;
     1786    data->deleteFunc = deleteFunc;
     1787    tr_runInEventThread( tor->session, removeTorrent, data );
    17601788}
    17611789
    17621790/**
  • gtk/tr-torrent.c

     
    4141{
    4242    tr_torrent *  handle;
    4343    gboolean      do_remove;
     44    gboolean      delete_local_data;
    4445};
    4546
    4647
    4748static void
    48 tr_torrent_init( GTypeInstance *  instance,
    49                  gpointer g_class UNUSED )
     49tr_torrent_init( GTypeInstance * instance, gpointer g_class UNUSED )
    5050{
    51     TrTorrent *               self = TR_TORRENT( instance );
    5251    struct TrTorrentPrivate * p;
     52    TrTorrent * self = TR_TORRENT( instance );
    5353
    54     p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self,
    55                                                   TR_TORRENT_TYPE,
    56                                                   struct TrTorrentPrivate );
     54    p = G_TYPE_INSTANCE_GET_PRIVATE( self, TR_TORRENT_TYPE, struct TrTorrentPrivate );
    5755    p->handle = NULL;
     56    p->do_remove = FALSE;
     57    p->delete_local_data = FALSE;
    5858
    59 #ifdef REFDBG
    60     g_message( "torrent %p init", self );
    61 #endif
     59    self->priv = p;
    6260}
    6361
    6462static int
     
    7876        if( self->priv->handle )
    7977        {
    8078            if( self->priv->do_remove )
    81                 tr_torrentRemove( self->priv->handle );
     79                tr_torrentRemove( self->priv->handle, self->priv->delete_local_data, gtr_file_trash_or_remove );
    8280            else
    8381                tr_torrentFree( self->priv->handle );
    8482        }
     
    208206}
    209207
    210208void
    211 tr_torrent_set_remove_flag( TrTorrent * gtor,
    212                             gboolean    do_remove )
     209tr_torrent_set_remove_flag( TrTorrent * gtor, gboolean flag )
    213210{
    214211    if( !isDisposed( gtor ) )
    215         gtor->priv->do_remove = do_remove;
     212        gtor->priv->do_remove = flag;
    216213}
    217214
    218215void
     216tr_torrent_set_delete_local_data_flag( TrTorrent * gtor, gboolean flag )
     217{
     218    if( !isDisposed( gtor ) )
     219        gtor->priv->delete_local_data = flag;
     220}
     221
     222
     223void
    219224tr_torrent_open_folder( TrTorrent * gtor )
    220225{
    221226    const tr_torrent * tor =  tr_torrent_handle( gtor );
  • gtk/tr-torrent.h

     
    7171                                    tr_ctor     * ctor,
    7272                                    int         * errcode );
    7373
    74 void           tr_torrent_set_remove_flag( TrTorrent *,
    75                                            gboolean );
     74void tr_torrent_set_remove_flag( TrTorrent *, gboolean );
    7675
     76void tr_torrent_set_delete_local_data_flag( TrTorrent *, gboolean );
     77
     78
    7779#endif
  • gtk/tr-core.c

     
    12661266        /* remove from the gui */
    12671267        gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
    12681268
    1269         /* maybe delete the downloaded files */
    1270         if( deleteFiles )
    1271             tr_torrentDeleteLocalData( tor, gtr_file_trash_or_remove );
    1272 
    12731269        /* remove the torrent */
     1270        tr_torrent_set_delete_local_data_flag( gtor, deleteFiles );
    12741271        tr_torrent_set_remove_flag( gtor, TRUE );
    12751272        gtr_warn_if_fail( G_OBJECT( gtor )->ref_count == 1 );
    12761273        g_object_unref( G_OBJECT( gtor ) ); /* remove the last refcount */