mirror of
https://github.com/transmission/transmission
synced 2025-02-01 03:43:43 +00:00
fix a race condition error in move-test
This commit is contained in:
parent
ae1ec6aab4
commit
3eb533336d
1 changed files with 12 additions and 25 deletions
|
@ -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; j<file->length; ++j)
|
||||
fputc ('\0', fp);
|
||||
fputc (((!complete) && (i==0) && (j<tor->info.pieceSize)) ? '\1' : '\0', fp);
|
||||
fclose (fp);
|
||||
|
||||
tr_free (dirname);
|
||||
|
@ -364,26 +366,11 @@ libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete)
|
|||
tr_free (path);
|
||||
}
|
||||
|
||||
sync ();
|
||||
|
||||
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);
|
||||
|
||||
if (complete)
|
||||
assert (tr_torrentStat(tor)->leftUntilDone == 0);
|
||||
else
|
||||
assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue