#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)
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; j<file->length; ++j)
- fputc ('\0', fp);
+ fputc (((!complete) && (i==0) && (j<tor->info.pieceSize)) ? '\1' : '\0', fp);
fclose (fp);
tr_free (dirname);
}
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);
}