forked from I2P_Developers/i2p.i2p
i2psnark: Fix autostart to start only torrents running previously,
save torrent running status on torrent stop when autostart is enabled, remove dup call to startTorrent() (ticket #2120)
This commit is contained in:
@ -78,4 +78,9 @@ public interface CompleteListener {
|
||||
* @since 0.9.31
|
||||
*/
|
||||
public void locked_saveComments(Snark snark, CommentSet comments);
|
||||
|
||||
/**
|
||||
* @since 0.9.42
|
||||
*/
|
||||
public boolean shouldAutoStart();
|
||||
}
|
||||
|
@ -648,7 +648,10 @@ public class Snark
|
||||
// TODO: Cache the config-in-mem to compare vs config-on-disk
|
||||
// (needed for auto-save to not double-save in some cases)
|
||||
long nowUploaded = getUploaded();
|
||||
boolean changed = storage.isChanged() || nowUploaded != savedUploaded;
|
||||
// If autoStart is enabled, always save the config, so we know
|
||||
// whether to start it up next time
|
||||
boolean changed = storage.isChanged() || nowUploaded != savedUploaded ||
|
||||
(completeListener != null && completeListener.shouldAutoStart());
|
||||
try {
|
||||
storage.close();
|
||||
} catch (IOException ioe) {
|
||||
|
@ -1537,6 +1537,7 @@ public class SnarkManager implements CompleteListener, ClientApp {
|
||||
*
|
||||
* @param filename the absolute path to save the metainfo to, generally ending in ".torrent"
|
||||
* @param baseFile may be null, if so look in dataDir
|
||||
* @param dontAutoStart must be false, AND running=true or null in torrent config file, to start
|
||||
* @throws RuntimeException via Snark.fatal()
|
||||
* @return success
|
||||
*/
|
||||
@ -1549,6 +1550,7 @@ public class SnarkManager implements CompleteListener, ClientApp {
|
||||
*
|
||||
* @param filename the absolute path to save the metainfo to, generally ending in ".torrent"
|
||||
* @param baseFile may be null, if so look in dataDir
|
||||
* @param dontAutoStart must be false, AND running=true or null in torrent config file, to start
|
||||
* @param dataDir must exist, or null to default to snark data directory
|
||||
* @throws RuntimeException via Snark.fatal()
|
||||
* @return success
|
||||
@ -1652,8 +1654,6 @@ public class SnarkManager implements CompleteListener, ClientApp {
|
||||
synchronized (_snarks) {
|
||||
putSnark(filename, torrent);
|
||||
}
|
||||
if (shouldAutoStart())
|
||||
torrent.startTorrent();
|
||||
} catch (IOException ioe) {
|
||||
// close before rename/delete for windows
|
||||
if (fis != null) try { fis.close(); fis = null; } catch (IOException ioe2) {}
|
||||
@ -2705,16 +2705,17 @@ public class SnarkManager implements CompleteListener, ClientApp {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("DirMon found: " + DataHelper.toString(foundNames) + " existing: " + DataHelper.toString(existingNames));
|
||||
// lets find new ones first...
|
||||
boolean shouldStart = shouldAutoStart();
|
||||
for (String name : foundNames) {
|
||||
if (existingNames.contains(name)) {
|
||||
// already known. noop
|
||||
} else {
|
||||
if (shouldAutoStart() && !_util.connect())
|
||||
if (shouldStart && !_util.connect())
|
||||
addMessage(_t("Unable to connect to I2P!"));
|
||||
try {
|
||||
// Snark.fatal() throws a RuntimeException
|
||||
// don't let one bad torrent kill the whole loop
|
||||
boolean ok = addTorrent(name, null, !shouldAutoStart());
|
||||
boolean ok = addTorrent(name, null, !shouldStart);
|
||||
if (!ok) {
|
||||
addMessage(_t("Error: Could not add the torrent {0}", name));
|
||||
_log.error("Unable to add the torrent " + name);
|
||||
|
@ -314,6 +314,11 @@ class UpdateRunner implements UpdateTask, CompleteListener {
|
||||
_smgr.locked_saveComments(snark, comments);
|
||||
}
|
||||
|
||||
/** @since 0.9.42 */
|
||||
public boolean shouldAutoStart() {
|
||||
return _smgr.shouldAutoStart();
|
||||
}
|
||||
|
||||
//////// end CompleteListener methods
|
||||
|
||||
private static String linkify(String url) {
|
||||
|
Reference in New Issue
Block a user