Changeset 13907


Ignore:
Timestamp:
Jan 31, 2013, 5:10:08 AM (8 years ago)
Author:
jordan
Message:

fix a race condition error in move-test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/libtransmission-test.c

    r13879 r13907  
    325325#define verify_and_block_until_done(tor) \
    326326  do { \
     327    do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    327328    tr_torrentVerify (tor); \
    328     do { \
    329       tr_wait_msec (10); \
    330     } while (tor->verifyState != TR_VERIFY_NONE); \
     329    do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
    331330  } while (0)
    332331
     
    347346      struct stat sb;
    348347
    349       path = tr_buildPath (tor->currentDir, file->name, NULL);
     348      if (!complete && (i==0))
     349        path = tr_strdup_printf ("%s%c%s.part", tor->currentDir, TR_PATH_DELIMITER, file->name);
     350      else
     351        path = tr_strdup_printf ("%s%c%s", tor->currentDir, TR_PATH_DELIMITER, file->name);
    350352      dirname = tr_dirname (path);
    351353      tr_mkdirp (dirname, 0700);
    352354      fp = fopen (path, "wb+");
    353355      for (j=0; j<file->length; ++j)
    354         fputc ('\0', fp);
     356        fputc (((!complete) && (i==0) && (j<tor->info.pieceSize)) ? '\1' : '\0', fp);
    355357      fclose (fp);
    356358
     
    366368
    367369  sync ();
    368 
    369   if (!complete)
    370     {
    371       FILE * fp;
    372       char * oldpath = tr_torrentFindFile (tor, 0);
    373       char * newpath = tr_strdup_printf ("%s.part", oldpath);
    374 
    375       rename (oldpath, newpath);
    376 
    377       /* invalidate one piece */
    378       fp = fopen (newpath, "rb+");
    379       fputc ('\1', fp);
    380       fclose (fp);
    381 
    382       tr_free (newpath);
    383       tr_free (oldpath);
    384 
    385       sync ();
    386       verify_and_block_until_done (tor);
    387       assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
    388     }
    389 }
     370  verify_and_block_until_done (tor);
     371
     372  if (complete)
     373    assert (tr_torrentStat(tor)->leftUntilDone == 0);
     374  else
     375    assert (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
     376}
Note: See TracChangeset for help on using the changeset viewer.