forked from I2P_Developers/i2p.i2p
I2PSnark:
- Fix NPE (#1615, h/t kytv) - Fix start/stop status resumption on restart (#766, h/t backup)
This commit is contained in:
@ -617,7 +617,6 @@ public class Snark
|
|||||||
* @since 0.9.1
|
* @since 0.9.1
|
||||||
*/
|
*/
|
||||||
public synchronized void stopTorrent(boolean fast) {
|
public synchronized void stopTorrent(boolean fast) {
|
||||||
stopped = true;
|
|
||||||
TrackerClient tc = trackerclient;
|
TrackerClient tc = trackerclient;
|
||||||
if (tc != null)
|
if (tc != null)
|
||||||
tc.halt(fast);
|
tc.halt(fast);
|
||||||
@ -630,15 +629,16 @@ public class Snark
|
|||||||
// (needed for auto-save to not double-save in some cases)
|
// (needed for auto-save to not double-save in some cases)
|
||||||
//boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
|
//boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
|
||||||
boolean changed = true;
|
boolean changed = true;
|
||||||
|
if (changed && completeListener != null)
|
||||||
|
completeListener.updateStatus(this);
|
||||||
try {
|
try {
|
||||||
storage.close();
|
storage.close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.out.println("Error closing " + torrent);
|
System.out.println("Error closing " + torrent);
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
if (changed && completeListener != null)
|
|
||||||
completeListener.updateStatus(this);
|
|
||||||
}
|
}
|
||||||
|
stopped = true;
|
||||||
if (pc != null && _peerCoordinatorSet != null)
|
if (pc != null && _peerCoordinatorSet != null)
|
||||||
_peerCoordinatorSet.remove(pc);
|
_peerCoordinatorSet.remove(pc);
|
||||||
if (_peerCoordinatorSet == null)
|
if (_peerCoordinatorSet == null)
|
||||||
|
@ -1272,7 +1272,13 @@ public class SnarkManager implements CompleteListener {
|
|||||||
}
|
}
|
||||||
// ok, snark created, now lets start it up or configure it further
|
// ok, snark created, now lets start it up or configure it further
|
||||||
Properties config = getConfig(torrent);
|
Properties config = getConfig(torrent);
|
||||||
boolean running = Boolean.parseBoolean(config.getProperty(PROP_META_RUNNING));
|
boolean running;
|
||||||
|
String prop = config.getProperty(PROP_META_RUNNING);
|
||||||
|
if(prop == null || Boolean.parseBoolean(prop)) {
|
||||||
|
running = true;
|
||||||
|
} else {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
// Were we running last time?
|
// Were we running last time?
|
||||||
if (!dontAutoStart && shouldAutoStart() && running) {
|
if (!dontAutoStart && shouldAutoStart() && running) {
|
||||||
torrent.startTorrent();
|
torrent.startTorrent();
|
||||||
@ -1432,10 +1438,12 @@ public class SnarkManager implements CompleteListener {
|
|||||||
Snark snark = getTorrentByInfoHash(metainfo.getInfoHash());
|
Snark snark = getTorrentByInfoHash(metainfo.getInfoHash());
|
||||||
if (snark != null) {
|
if (snark != null) {
|
||||||
addMessage(_("Torrent with this info hash is already running: {0}", snark.getBaseName()));
|
addMessage(_("Torrent with this info hash is already running: {0}", snark.getBaseName()));
|
||||||
|
saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, false); // no file priorities
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, true); // no file priorities
|
||||||
}
|
}
|
||||||
// so addTorrent won't recheck
|
// so addTorrent won't recheck
|
||||||
saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, snark.isStopped()); // no file priorities
|
|
||||||
try {
|
try {
|
||||||
locked_writeMetaInfo(metainfo, filename, areFilesPublic());
|
locked_writeMetaInfo(metainfo, filename, areFilesPublic());
|
||||||
// hold the lock for a long time
|
// hold the lock for a long time
|
||||||
|
Reference in New Issue
Block a user