forked from I2P_Developers/i2p.i2p
i2psnark: Fix bad completion status after recheck (ticket #2046)
Only occurred if torrent had previously run, was previously incomplete, and was now complete. Also fixed changed-after-recheck logic to be precise.
This commit is contained in:
@ -170,7 +170,24 @@ public class BitField
|
||||
return count >= size;
|
||||
}
|
||||
|
||||
@Override
|
||||
/** @since 0.9.33 */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (count << 16) ^ size;
|
||||
}
|
||||
|
||||
/** @since 0.9.33 */
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof BitField))
|
||||
return false;
|
||||
BitField bf = (BitField) o;
|
||||
return count == bf.count() &&
|
||||
size == bf.size() &&
|
||||
Arrays.equals(bitfield, bf.getFieldBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
// Not very efficient
|
||||
|
@ -892,9 +892,7 @@ public class Storage implements Closeable
|
||||
* @since 0.9.23
|
||||
*/
|
||||
public boolean recheck() throws IOException {
|
||||
int previousNeeded = needed;
|
||||
checkCreateFiles(true);
|
||||
boolean changed = previousNeeded != needed;
|
||||
boolean changed = checkCreateFiles(true);
|
||||
if (listener != null && changed)
|
||||
listener.setWantedPieces(this);
|
||||
return changed;
|
||||
@ -910,19 +908,23 @@ public class Storage implements Closeable
|
||||
* @param recheck if true, this is a check after we downloaded the
|
||||
* last piece, and we don't modify the global bitfield unless
|
||||
* the check fails.
|
||||
* @return true if changed (only valid if recheck == true)
|
||||
*/
|
||||
private void checkCreateFiles(boolean recheck) throws IOException {
|
||||
private boolean checkCreateFiles(boolean recheck) throws IOException {
|
||||
synchronized(this) {
|
||||
_isChecking = true;
|
||||
try {
|
||||
locked_checkCreateFiles(recheck);
|
||||
return locked_checkCreateFiles(recheck);
|
||||
} finally {
|
||||
_isChecking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void locked_checkCreateFiles(boolean recheck) throws IOException
|
||||
/**
|
||||
* @return true if changed (only valid if recheck == true)
|
||||
*/
|
||||
private boolean locked_checkCreateFiles(boolean recheck) throws IOException
|
||||
{
|
||||
_checkProgress.set(0);
|
||||
// Whether we are resuming or not,
|
||||
@ -1033,9 +1035,11 @@ public class Storage implements Closeable
|
||||
|
||||
// do this here so we don't confuse the user during checking
|
||||
needed = need;
|
||||
if (recheck && need > 0) {
|
||||
// whoops, recheck failed
|
||||
boolean rv = false;
|
||||
if (recheck) {
|
||||
// FIXME bogus synch
|
||||
synchronized(bitfield) {
|
||||
rv = !bfield.equals(bitfield);
|
||||
bitfield = bfield;
|
||||
}
|
||||
}
|
||||
@ -1045,6 +1049,7 @@ public class Storage implements Closeable
|
||||
if (needed <= 0)
|
||||
listener.storageCompleted(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user