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