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
|
||||
*/
|
||||
public synchronized void stopTorrent(boolean fast) {
|
||||
stopped = true;
|
||||
TrackerClient tc = trackerclient;
|
||||
if (tc != null)
|
||||
tc.halt(fast);
|
||||
@ -630,15 +629,16 @@ public class Snark
|
||||
// (needed for auto-save to not double-save in some cases)
|
||||
//boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
|
||||
boolean changed = true;
|
||||
if (changed && completeListener != null)
|
||||
completeListener.updateStatus(this);
|
||||
try {
|
||||
storage.close();
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Error closing " + torrent);
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
if (changed && completeListener != null)
|
||||
completeListener.updateStatus(this);
|
||||
}
|
||||
stopped = true;
|
||||
if (pc != null && _peerCoordinatorSet != null)
|
||||
_peerCoordinatorSet.remove(pc);
|
||||
if (_peerCoordinatorSet == null)
|
||||
|
@ -1272,7 +1272,13 @@ public class SnarkManager implements CompleteListener {
|
||||
}
|
||||
// ok, snark created, now lets start it up or configure it further
|
||||
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?
|
||||
if (!dontAutoStart && shouldAutoStart() && running) {
|
||||
torrent.startTorrent();
|
||||
@ -1432,10 +1438,12 @@ public class SnarkManager implements CompleteListener {
|
||||
Snark snark = getTorrentByInfoHash(metainfo.getInfoHash());
|
||||
if (snark != null) {
|
||||
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;
|
||||
} else {
|
||||
saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, true); // no file priorities
|
||||
}
|
||||
// so addTorrent won't recheck
|
||||
saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, snark.isStopped()); // no file priorities
|
||||
try {
|
||||
locked_writeMetaInfo(metainfo, filename, areFilesPublic());
|
||||
// hold the lock for a long time
|
||||
|
Reference in New Issue
Block a user