~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to libtransmission/verify.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio, Andrew Starr-Bochicchio, Martin Pitt
  • Date: 2009-02-26 11:55:50 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20090226115550-3rnhgt9qhe3y6g74
Tags: 1.50-1ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian unstable (LP: #329161), remaining changes:
 - debian/control: 
  + Added replaces & provides clutch (now included as part of transmission).
  + Build-depends on quilt.
 - debian/rules: 
  + Uncommented "include /usr/share/quilt/quilt.make".
  + Added patch/unpatch targets for Quilt.
  + Create a PO template during package build.
 - 20_add_X-Ubuntu-Gettext-Domain.diff: Add X-Ubuntu-Gettext-Domain 
   to .desktop file.

[ Martin Pitt ]
* Add 01_check_notification_actions.diff: Check if notification
  agent supports actions, and do not use actions if not. (LP: #334252)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
 
2
 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: verify.c 6975 2008-10-28 15:13:07Z charles $
 
10
 * $Id: verify.c 7813 2009-01-29 18:18:24Z charles $
11
11
 */
12
12
 
13
13
#include <unistd.h> /* S_ISREG */
34
34
};
35
35
 
36
36
static void
37
 
fireCheckDone( tr_torrent *      torrent,
38
 
               tr_verify_done_cb verify_done_cb )
 
37
fireCheckDone( tr_torrent * tor, tr_verify_done_cb verify_done_cb )
39
38
{
 
39
    assert( tr_isTorrent( tor ) );
 
40
 
40
41
    if( verify_done_cb )
41
 
        verify_done_cb( torrent );
 
42
        verify_done_cb( tor );
42
43
}
43
44
 
44
45
static struct verify_node currentNode;
45
 
 
46
 
static tr_list *          verifyList = NULL;
47
 
 
48
 
static tr_thread *        verifyThread = NULL;
49
 
 
50
 
static int                stopCurrent = FALSE;
 
46
static tr_list * verifyList = NULL;
 
47
static tr_thread * verifyThread = NULL;
 
48
static int stopCurrent = FALSE;
51
49
 
52
50
static tr_lock*
53
51
getVerifyLock( void )
60
58
}
61
59
 
62
60
static int
63
 
checkFile( tr_torrent *    tor,
64
 
           tr_file_index_t fileIndex,
65
 
           int *           abortFlag )
 
61
checkFile( tr_torrent      * tor,
 
62
           void            * buffer,
 
63
           size_t            buflen,
 
64
           tr_file_index_t   fileIndex,
 
65
           int             * abortFlag )
66
66
{
67
67
    tr_piece_index_t i;
68
68
    int              changed = FALSE;
84
84
        }
85
85
        else if( !tr_torrentIsPieceChecked( tor, i ) )
86
86
        {
87
 
            const int      wasComplete = tr_cpPieceIsComplete(
88
 
                tor->completion, i );
 
87
            const int wasComplete = tr_cpPieceIsComplete( &tor->completion, i );
89
88
 
90
 
            if( tr_ioTestPiece( tor, i ) ) /* yay */
 
89
            if( tr_ioTestPiece( tor, i, buffer, buflen ) ) /* yay */
91
90
            {
92
91
                tr_torrentSetHasPiece( tor, i, TRUE );
93
92
                if( !wasComplete )
119
118
static void
120
119
verifyThreadFunc( void * unused UNUSED )
121
120
{
122
 
    for( ; ; )
 
121
    for( ;; )
123
122
    {
124
123
        int                  changed = 0;
125
124
        tr_file_index_t      i;
126
 
        tr_torrent *         tor;
 
125
        tr_torrent         * tor;
127
126
        struct verify_node * node;
 
127
        void               * buffer;
128
128
 
129
129
        tr_lockLock( getVerifyLock( ) );
130
130
        stopCurrent = FALSE;
141
141
        tr_free( node );
142
142
        tr_lockUnlock( getVerifyLock( ) );
143
143
 
 
144
        tr_torinf( tor, _( "Verifying torrent" ) );
 
145
        assert( tr_isTorrent( tor ) );
144
146
        tor->verifyState = TR_VERIFY_NOW;
145
 
 
146
 
        tr_torinf( tor, _( "Verifying torrent" ) );
 
147
        buffer = tr_new( uint8_t, tor->info.pieceSize );
147
148
        for( i = 0; i < tor->info.fileCount && !stopCurrent; ++i )
148
 
            changed |= checkFile( tor, i, &stopCurrent );
149
 
 
 
149
            changed |= checkFile( tor, buffer, tor->info.pieceSize, i, &stopCurrent );
 
150
        tr_free( buffer );
150
151
        tor->verifyState = TR_VERIFY_NONE;
 
152
        assert( tr_isTorrent( tor ) );
151
153
 
152
154
        if( !stopCurrent )
153
155
        {
167
169
{
168
170
    const int uncheckedCount = tr_torrentCountUncheckedPieces( tor );
169
171
 
 
172
    assert( tr_isTorrent( tor ) );
 
173
 
170
174
    if( !uncheckedCount )
171
175
    {
172
176
        /* doesn't need to be checked... */
208
212
    tr_lock * lock = getVerifyLock( );
209
213
    tr_lockLock( lock );
210
214
 
 
215
    assert( tr_isTorrent( tor ) );
 
216
 
211
217
    found = ( tor == currentNode.torrent )
212
218
         || ( tr_list_find( verifyList, tor, compareVerifyByTorrent ) != NULL );
213
219
 
219
225
tr_verifyRemove( tr_torrent * tor )
220
226
{
221
227
    tr_lock * lock = getVerifyLock( );
222
 
 
223
228
    tr_lockLock( lock );
224
229
 
 
230
    assert( tr_isTorrent( tor ) );
 
231
 
225
232
    if( tor == currentNode.torrent )
226
233
    {
227
234
        stopCurrent = TRUE;