Changeset b4e0fe12


Ignore:
Timestamp:
Jan 12, 2011 1:54:41 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b55bfd03
Parents:
1ae6c28
Message:

dont update globals until end of storage check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    r1ae6c28 rb4e0fe12  
    539539      // the following sets the needed variable
    540540      changed = true;
    541       checkCreateFiles();
     541      checkCreateFiles(false);
    542542    }
    543543    if (complete()) {
     
    650650   * This is called at the beginning, and at presumed completion,
    651651   * so we have to be careful about locking.
    652    */
    653   private void checkCreateFiles() throws IOException
     652   *
     653   * @param recheck if true, this is a check after we downloaded the
     654   *        last piece, and we don't modify the global bitfield unless
     655   *        the check fails.
     656   */
     657  private void checkCreateFiles(boolean recheck) throws IOException
    654658  {
    655659    // Whether we are resuming or not,
     
    658662
    659663    _probablyComplete = true;
    660     needed = metainfo.getPieces();
     664    // use local variables during the check
     665    int need = metainfo.getPieces();
     666    BitField bfield;
     667    if (recheck) {
     668        bfield = new BitField(need);
     669    } else {
     670        bfield = bitfield;
     671    }
    661672
    662673    // Make sure all files are available and of correct length
     
    719730            if (correctHash)
    720731              {
    721                 bitfield.set(i);
    722                 needed--;
     732                bfield.set(i);
     733                need--;
    723734              }
    724735
     
    739750    //  }
    740751    //}
     752
     753    // do this here so we don't confuse the user during checking
     754    needed = need;
     755    if (recheck && need > 0) {
     756        // whoops, recheck failed
     757        synchronized(bitfield) {
     758            bitfield = bfield;
     759        }
     760    }
    741761
    742762    if (listener != null) {
     
    904924      // and also call listener.storageCompleted() if the double-check
    905925      // was successful.
    906       // Todo: set a listener variable so the web shows "checking" and don't
    907       // have the user panic when completed amount goes to zero temporarily?
    908       needed = metainfo.getPieces();
    909       bitfield = new BitField(needed);
    910       checkCreateFiles();
     926      checkCreateFiles(true);
    911927      if (needed > 0) {
    912928        if (listener != null)
Note: See TracChangeset for help on using the changeset viewer.