if (verify)
{
verify = false;
- tr_torrentVerify (tor);
+ tr_torrentVerify (tor, NULL, NULL);
}
for (;;)
tr_torrentSetDownloadDir (o->tor, o->downloadDir);
gtk_widget_set_sensitive (o->file_list, tr_torrentHasMetadata (o->tor));
gtr_file_list_set_torrent (o->file_list, tr_torrentId (o->tor));
- tr_torrentVerify (o->tor);
+ tr_torrentVerify (o->tor, NULL, NULL);
}
}
while [ $err -eq 0 ]; do
count=$((count+1))
echo starting run number $count
- make check
+ ./rename-test
err=$?
done
#include "transmission.h"
#include "platform.h" /* TR_PATH_DELIMETER */
#include "torrent.h"
+#include "trevent.h"
#include "libtransmission-test.h"
bool verbose = false;
return tor;
}
-#define verify_and_block_until_done(tor) \
- do { \
- do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
- tr_torrentVerify (tor); \
- do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
- } while (0)
-
-
void
libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete)
{
}
sync ();
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
if (complete)
assert (tr_torrentStat(tor)->leftUntilDone == 0);
else
assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
}
+
+/***
+****
+***/
+
+static void
+onVerifyDone (tr_torrent * tor UNUSED, bool aborted UNUSED, void * done)
+{
+ *(bool*)done = true;
+}
+
+void
+libttest_blockingTorrentVerify (tr_torrent * tor)
+{
+ bool done = false;
+
+ assert (session != NULL);
+ assert (!tr_amInEventThread (session));
+
+ tr_torrentVerify (tor, onVerifyDone, &done);
+ while (!done)
+ tr_wait_msec (10);
+}
void libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete);
tr_torrent * libtransmission_test_zero_torrent_init (void);
+void libttest_blockingTorrentVerify (tr_torrent * tor);
+
#endif /* !LIBTRANSMISSION_TEST_H */
****
***/
-#define verify_and_block_until_done(tor) \
- do { \
- do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
- tr_torrentVerify (tor); \
- do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
- } while (0)
-
static void
zeroes_completeness_func (tr_torrent * torrent UNUSED,
tr_completeness completeness,
tr_free (zero_block);
}
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
check_int_eq (0, tr_torrentStat(tor)->leftUntilDone);
while ((completeness==completeness_unset) && (time(NULL)<=deadline))
****
***/
-#define verify_and_block_until_done(tor) \
- do { \
- do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
- tr_torrentVerify (tor); \
- do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
- } while (0)
-
#define check_have_none(tor, totalSize) \
do { \
const tr_stat * st = tr_torrentStat(tor); \
check (!tor->info.files[0].is_renamed);
/* sanity check the (empty) stats */
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
check_have_none (tor, totalSize);
create_single_file_torrent_contents (tor->currentDir);
/* sanity check the stats again, now that we've added the file */
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
st = tr_torrentStat (tor);
check_int_eq (TR_STATUS_STOPPED, st->activity);
check_int_eq (TR_STAT_OK, st->error);
check_streq (expected_files[i], files[i].name);
/* sanity check the (empty) stats */
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
check_have_none (tor, totalSize);
/* build the local data */
create_multifile_torrent_contents (tor->currentDir);
/* sanity check the (full) stats */
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
st = tr_torrentStat (tor);
check_int_eq (TR_STATUS_STOPPED, st->activity);
check_int_eq (TR_STAT_OK, st->error);
tr_free (tmp);
tr_free (str);
sync ();
- verify_and_block_until_done (tor);
+ libttest_blockingTorrentVerify (tor);
testFileExistsAndConsistsOfThisString (tor, 0, expected_contents[0]);
for (i=1; i<=2; ++i)
{
for (i = 0; i < torrentCount; ++i)
{
tr_torrent * tor = torrents[i];
- tr_torrentVerify (tor);
+ tr_torrentVerify (tor, NULL, NULL);
notify (session, TR_RPC_TORRENT_CHANGED, tor);
}
if (isNewTorrent)
{
tor->startAfterVerify = doStart;
- tr_torrentVerify (tor);
+ tr_torrentVerify (tor, NULL, NULL);
}
else if (doStart)
{
torrentStart (tor, true);
}
+struct verify_data
+{
+ bool aborted;
+ tr_torrent * tor;
+ tr_verify_done_func callback_func;
+ void * callback_data;
+};
+
static void
-torrentRecheckDoneImpl (void * vtor)
+onVerifyDoneThreadFunc (void * vdata)
{
- tr_torrent * tor = vtor;
- assert (tr_isTorrent (tor));
+ struct verify_data * data = vdata;
+ tr_torrent * tor = data->tor;
+ if (!data->aborted)
tr_torrentRecheckCompleteness (tor);
- if (tor->startAfterVerify) {
- tor->startAfterVerify = false;
- torrentStart (tor, false);
+ if (data->callback_func != NULL)
+ (*data->callback_func)(tor, data->aborted, data->callback_data);
+
+ if (!data->aborted && tor->startAfterVerify)
+ {
+ tor->startAfterVerify = false;
+ torrentStart (tor, false);
}
+
+ tr_free (data);
}
static void
-torrentRecheckDoneCB (tr_torrent * tor)
+onVerifyDone (tr_torrent * tor, bool aborted, void * vdata)
{
- assert (tr_isTorrent (tor));
-
- tr_runInEventThread (tor->session, torrentRecheckDoneImpl, tor);
+ struct verify_data * data = vdata;
+ assert (data->tor == tor);
+ data->aborted = aborted;
+ tr_runInEventThread (tor->session, onVerifyDoneThreadFunc, data);
}
static void
-verifyTorrent (void * vtor)
+verifyTorrent (void * vdata)
{
- bool startAfter;
- tr_torrent * tor = vtor;
-
- tr_sessionLock (tor->session);
-
- /* if the torrent's already being verified, stop it */
- tr_verifyRemove (tor);
+ bool startAfter;
+ struct verify_data * data = vdata;
+ tr_torrent * tor = data->tor;
+ tr_sessionLock (tor->session);
- startAfter = (tor->isRunning || tor->startAfterVerify) && !tor->isStopping;
-
- if (tor->isRunning)
- tr_torrentStop (tor);
+ /* if the torrent's already being verified, stop it */
+ tr_verifyRemove (tor);
- tor->startAfterVerify = startAfter;
+ startAfter = (tor->isRunning || tor->startAfterVerify) && !tor->isStopping;
+ if (tor->isRunning)
+ tr_torrentStop (tor);
+ tor->startAfterVerify = startAfter;
- if (setLocalErrorIfFilesDisappeared (tor))
- tor->startAfterVerify = false;
- else
- tr_verifyAdd (tor, torrentRecheckDoneCB);
+ if (setLocalErrorIfFilesDisappeared (tor))
+ tor->startAfterVerify = false;
+ else
+ tr_verifyAdd (tor, onVerifyDone, data);
- tr_sessionUnlock (tor->session);
+ tr_sessionUnlock (tor->session);
}
void
-tr_torrentVerify (tr_torrent * tor)
+tr_torrentVerify (tr_torrent * tor,
+ tr_verify_done_func callback_func,
+ void * callback_data)
{
- if (tr_isTorrent (tor))
- tr_runInEventThread (tor->session, verifyTorrent, tor);
+ struct verify_data * data;
+
+ data = tr_new (struct verify_data, 1);
+ data->tor = tor;
+ data->aborted = false;
+ data->callback_func = callback_func;
+ data->callback_data = callback_data;
+ tr_runInEventThread (tor->session, verifyTorrent, data);
}
void
typedef void (tr_torrent_metadata_func)(tr_torrent * torrent,
- void * user_data);
+ void * user_data);
/**
* Register to be notified whenever a torrent changes from
* having incomplete metadata to having complete metadata.
float * tab,
int size);
-void tr_torrentVerify (tr_torrent * torrent);
+/**
+ * Callback function invoked when a torrent finishes being verified.
+ *
+ * @param torrent the torrent that was verified
+ * @param aborted true if the verify ended prematurely for some reason,
+ * such as tr_torrentStop() or tr_torrentSetLocation()
+ * being called during verification.
+ * @param callback_data the user-defined pointer from tr_torrentVerify()
+ */
+typedef void (*tr_verify_done_func)(tr_torrent * torrent,
+ bool aborted,
+ void * user_data);
+
+/**
+ * Queue a torrent for verification.
+ *
+ * If callback_func is non-NULL, it will be called from the libtransmission
+ * thread after the torrent's completness state is updated after the
+ * file verification pass.
+ */
+void tr_torrentVerify (tr_torrent * torrent,
+ tr_verify_done_func callback_func_or_NULL,
+ void * callback_data_or_NULL);
/***********************************************************************
* tr_info
struct verify_node
{
- tr_torrent * torrent;
- tr_verify_done_cb verify_done_cb;
- uint64_t current_size;
+ tr_torrent * torrent;
+ tr_verify_done_func callback_func;
+ void * callback_data;
+ uint64_t current_size;
};
-static void
-fireCheckDone (tr_torrent * tor, tr_verify_done_cb verify_done_cb)
-{
- assert (tr_isTorrent (tor));
-
- if (verify_done_cb)
- verify_done_cb (tor);
-}
-
static struct verify_node currentNode;
static tr_list * verifyList = NULL;
static tr_thread * verifyThread = NULL;
tr_torrentSetVerifyState (tor, TR_VERIFY_NONE);
assert (tr_isTorrent (tor));
- if (!stopCurrent)
- {
- if (changed)
- tr_torrentSetDirty (tor);
- fireCheckDone (tor, currentNode.verify_done_cb);
- }
+ if (!stopCurrent && changed)
+ tr_torrentSetDirty (tor);
+
+ if (currentNode.callback_func)
+ (*currentNode.callback_func)(tor, stopCurrent, currentNode.callback_data);
}
verifyThread = NULL;
}
void
-tr_verifyAdd (tr_torrent * tor, tr_verify_done_cb verify_done_cb)
+tr_verifyAdd (tr_torrent * tor,
+ tr_verify_done_func callback_func,
+ void * callback_data)
{
struct verify_node * node;
node = tr_new (struct verify_node, 1);
node->torrent = tor;
- node->verify_done_cb = verify_done_cb;
+ node->callback_func = callback_func;
+ node->callback_data = callback_data;
node->current_size = tr_torrentGetCurrentSizeOnDisk (tor);
tr_lockLock (getVerifyLock ());
* @{
*/
-typedef void (*tr_verify_done_cb)(tr_torrent * tor);
-
-void tr_verifyAdd (tr_torrent * tor,
- tr_verify_done_cb recheck_done_cb);
+void tr_verifyAdd (tr_torrent * tor,
+ tr_verify_done_func callback_func,
+ void * callback_user_data);
void tr_verifyRemove (tr_torrent * tor);
- (void) resetCache
{
- tr_torrentVerify(fHandle);
+ tr_torrentVerify(fHandle, NULL, NULL);
[self update];
}