diff --git a/libtransmission/libtransmission-test.c b/libtransmission/libtransmission-test.c index a5fcc697d..0ecd2ad0d 100644 --- a/libtransmission/libtransmission-test.c +++ b/libtransmission/libtransmission-test.c @@ -324,10 +324,9 @@ libtransmission_test_zero_torrent_init (void) #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); \ + do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \ } while (0) @@ -346,12 +345,15 @@ libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete) const tr_file * file = &tor->info.files[i]; struct stat sb; - path = tr_buildPath (tor->currentDir, file->name, NULL); + if (!complete && (i==0)) + path = tr_strdup_printf ("%s%c%s.part", tor->currentDir, TR_PATH_DELIMITER, file->name); + else + path = tr_strdup_printf ("%s%c%s", tor->currentDir, TR_PATH_DELIMITER, file->name); dirname = tr_dirname (path); tr_mkdirp (dirname, 0700); fp = fopen (path, "wb+"); for (j=0; jlength; ++j) - fputc ('\0', fp); + fputc (((!complete) && (i==0) && (jinfo.pieceSize)) ? '\1' : '\0', fp); fclose (fp); tr_free (dirname); @@ -365,25 +367,10 @@ libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete) } sync (); + verify_and_block_until_done (tor); - if (!complete) - { - FILE * fp; - char * oldpath = tr_torrentFindFile (tor, 0); - char * newpath = tr_strdup_printf ("%s.part", oldpath); - - rename (oldpath, newpath); - - /* invalidate one piece */ - fp = fopen (newpath, "rb+"); - fputc ('\1', fp); - fclose (fp); - - tr_free (newpath); - tr_free (oldpath); - - sync (); - verify_and_block_until_done (tor); - assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize); - } + if (complete) + assert (tr_torrentStat(tor)->leftUntilDone == 0); + else + assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize); }