forked from I2P_Developers/i2p.i2p
i2psnark: Add check progress output
This commit is contained in:
@ -745,6 +745,18 @@ public class Snark
|
||||
return storage != null && storage.isChecking();
|
||||
}
|
||||
|
||||
/**
|
||||
* If checking is in progress, return completion 0-100,
|
||||
* else return 100.
|
||||
* @since 0.9.23
|
||||
*/
|
||||
public double getCheckingProgress() {
|
||||
if (storage != null && storage.isChecking())
|
||||
return storage.getCheckingProgress();
|
||||
else
|
||||
return 100.0d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disk allocation (ballooning) in progress.
|
||||
* @since 0.9.3
|
||||
|
@ -73,6 +73,7 @@ public class Storage implements Closeable
|
||||
private boolean changed;
|
||||
private volatile boolean _isChecking;
|
||||
private final AtomicInteger _allocateCount = new AtomicInteger();
|
||||
private final AtomicInteger _checkProgress = new AtomicInteger();
|
||||
|
||||
/** The default piece size. */
|
||||
private static final int DEFAULT_PIECE_SIZE = 256*1024;
|
||||
@ -311,6 +312,18 @@ public class Storage implements Closeable
|
||||
return _isChecking;
|
||||
}
|
||||
|
||||
/**
|
||||
* If checking is in progress, return completion 0-100,
|
||||
* else return 100.
|
||||
* @since 0.9.23
|
||||
*/
|
||||
public double getCheckingProgress() {
|
||||
if (_isChecking)
|
||||
return _checkProgress.get() / (double) pieces;
|
||||
else
|
||||
return 100.0d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disk allocation (ballooning) in progress.
|
||||
* Always false on Windows.
|
||||
@ -869,6 +882,7 @@ public class Storage implements Closeable
|
||||
|
||||
private void locked_checkCreateFiles(boolean recheck) throws IOException
|
||||
{
|
||||
_checkProgress.set(0);
|
||||
// Whether we are resuming or not,
|
||||
// if any of the files already exists we assume we are resuming.
|
||||
boolean resume = false;
|
||||
@ -885,13 +899,16 @@ public class Storage implements Closeable
|
||||
|
||||
// Make sure all files are available and of correct length
|
||||
// The files should all exist as they have been created with zero length by createFilesFromNames()
|
||||
long lengthProgress = 0;
|
||||
for (TorrentFile tf : _torrentFiles)
|
||||
{
|
||||
long length = tf.RAFfile.length();
|
||||
lengthProgress += tf.length;
|
||||
if(tf.RAFfile.exists() && length == tf.length)
|
||||
{
|
||||
if (listener != null)
|
||||
listener.storageAllocated(this, length);
|
||||
_checkProgress.set(0);
|
||||
resume = true; // XXX Could dynamicly check
|
||||
}
|
||||
else if (length == 0) {
|
||||
@ -903,6 +920,8 @@ public class Storage implements Closeable
|
||||
tf.closeRAF();
|
||||
} catch (IOException ioe) {}
|
||||
}
|
||||
if (!resume)
|
||||
_checkProgress.set((int) (pieces * lengthProgress / total_length));
|
||||
} else {
|
||||
String msg = "File '" + tf.name + "' exists, but has wrong length (expected " +
|
||||
tf.length + " but found " + length + ") - repairing corruption";
|
||||
@ -911,6 +930,7 @@ public class Storage implements Closeable
|
||||
_log.error(msg);
|
||||
changed = true;
|
||||
resume = true;
|
||||
_checkProgress.set(0);
|
||||
_probablyComplete = false; // to force RW
|
||||
synchronized(tf) {
|
||||
RandomAccessFile raf = tf.checkRAF();
|
||||
@ -931,6 +951,7 @@ public class Storage implements Closeable
|
||||
long pieceEnd = 0;
|
||||
for (int i = 0; i < pieces; i++)
|
||||
{
|
||||
_checkProgress.set(i);
|
||||
int length = getUncheckedPiece(i, piece);
|
||||
boolean correctHash = metainfo.checkPiece(i, piece, 0, length);
|
||||
// close as we go so we don't run out of file descriptors
|
||||
@ -957,6 +978,7 @@ public class Storage implements Closeable
|
||||
}
|
||||
}
|
||||
|
||||
_checkProgress.set(pieces);
|
||||
_probablyComplete = complete();
|
||||
// close all the files so we don't end up with a zillion open ones;
|
||||
// we will reopen as needed
|
||||
|
@ -1471,7 +1471,8 @@ public class I2PSnarkServlet extends BasicServlet {
|
||||
String statusString;
|
||||
if (snark.isChecking()) {
|
||||
statusString = toThemeImg("stalled", "", _("Checking")) + "</td>" +
|
||||
"<td class=\"snarkTorrentStatus\">" + _("Checking");
|
||||
"<td class=\"snarkTorrentStatus\">" + _("Checking") + ' ' +
|
||||
(new DecimalFormat("0.00%")).format(snark.getCheckingProgress());
|
||||
} else if (snark.isAllocating()) {
|
||||
statusString = toThemeImg("stalled", "", _("Allocating")) + "</td>" +
|
||||
"<td class=\"snarkTorrentStatus\">" + _("Allocating");
|
||||
@ -2924,8 +2925,9 @@ public class I2PSnarkServlet extends BasicServlet {
|
||||
buf.append("<tr><td>");
|
||||
toThemeImg(buf, "file");
|
||||
if (snark.isChecking()) {
|
||||
buf.append(" <b>").append(_("Checking")).append("…</b> ")
|
||||
.append("<a href=\"").append(base).append("\">")
|
||||
buf.append(" <b>").append(_("Checking")).append("… ")
|
||||
.append((new DecimalFormat("0.00%")).format(snark.getCheckingProgress()))
|
||||
.append(" <a href=\"").append(base).append("\">")
|
||||
.append(_("Refresh page for results")).append("</a>");
|
||||
} else if (snark.isStarting()) {
|
||||
buf.append(" <b>").append(_("Starting")).append("…</b>");
|
||||
|
Reference in New Issue
Block a user