mirror of
https://github.com/transmission/transmission
synced 2025-03-17 17:25:32 +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) \
|
#define verify_and_block_until_done(tor) \
|
||||||
do { \
|
do { \
|
||||||
|
do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
|
||||||
tr_torrentVerify (tor); \
|
tr_torrentVerify (tor); \
|
||||||
do { \
|
do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
|
||||||
tr_wait_msec (10); \
|
|
||||||
} while (tor->verifyState != TR_VERIFY_NONE); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -346,12 +345,15 @@ libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete)
|
||||||
const tr_file * file = &tor->info.files[i];
|
const tr_file * file = &tor->info.files[i];
|
||||||
struct stat sb;
|
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);
|
dirname = tr_dirname (path);
|
||||||
tr_mkdirp (dirname, 0700);
|
tr_mkdirp (dirname, 0700);
|
||||||
fp = fopen (path, "wb+");
|
fp = fopen (path, "wb+");
|
||||||
for (j=0; j<file->length; ++j)
|
for (j=0; j<file->length; ++j)
|
||||||
fputc ('\0', fp);
|
fputc (((!complete) && (i==0) && (j<tor->info.pieceSize)) ? '\1' : '\0', fp);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
tr_free (dirname);
|
tr_free (dirname);
|
||||||
|
@ -365,25 +367,10 @@ libtransmission_test_zero_torrent_populate (tr_torrent * tor, bool complete)
|
||||||
}
|
}
|
||||||
|
|
||||||
sync ();
|
sync ();
|
||||||
|
verify_and_block_until_done (tor);
|
||||||
|
|
||||||
if (!complete)
|
if (complete)
|
||||||
{
|
assert (tr_torrentStat(tor)->leftUntilDone == 0);
|
||||||
FILE * fp;
|
else
|
||||||
char * oldpath = tr_torrentFindFile (tor, 0);
|
assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue