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:
zzz
2017-11-16 02:26:29 +00:00
parent e78081f33b
commit e9ff0c2882
4 changed files with 36 additions and 10 deletions

View File

@ -170,6 +170,23 @@ public class BitField
return count >= size;
}
/** @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()
{

View File

@ -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;
}
/**

View File

@ -1,3 +1,7 @@
2017-11-16 zzz
* i2psnark: Fix bad completion status after recheck (ticket #2046)
* Jetty 9.2.22
2017-11-07 zzz
* Utils: Constant-time password check

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 1;
public final static long BUILD = 2;
/** for example "-test" */
public final static String EXTRA = "";