From 8ff6a84a4e59a20413c8b0a96b705a6d66c4596f Mon Sep 17 00:00:00 2001 From: Lode Hoste Date: Mon, 13 Apr 2015 21:29:48 +0200 Subject: [PATCH] Limit retries when create the config file --- .../com/nutomic/syncthingandroid/util/ConfigXml.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index a05d8366..2ed34d01 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -3,6 +3,7 @@ package com.nutomic.syncthingandroid.util; import android.content.Context; import android.os.Environment; import android.util.Log; +import android.widget.Toast; import com.nutomic.syncthingandroid.syncthing.SyncthingRunnable; import com.nutomic.syncthingandroid.syncthing.SyncthingService; @@ -53,8 +54,7 @@ public class ConfigXml { generateKeysConfig(context); } - // This could cause an infinite loop, maybe we should add a counter, too. - do { + for (int i = 0; i < 10 && mConfig == null; i++) { try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); mConfig = db.parse(mConfigFile); @@ -69,7 +69,10 @@ public class ConfigXml { isFirstStart = true; mConfigFile = getConfigFile(context); } - } while (mConfig == null); + } + if (mConfig == null) { + Toast.makeText(context, "Failed to create a Syncthing config. Syncthing will not start!", Toast.LENGTH_LONG).show(); + } if (isFirstStart) { changeDefaultFolder();