From b9c76ff062c4166549ee54e723e5a384d2b5624e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 12 Mar 2016 19:30:38 +0100 Subject: [PATCH] Shutdown syncthing before importing a config (fixes #570). --- .../nutomic/syncthingandroid/fragments/SettingsFragment.java | 3 ++- .../nutomic/syncthingandroid/syncthing/SyncthingRunnable.java | 2 +- .../nutomic/syncthingandroid/syncthing/SyncthingService.java | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java index ab3e7945..e71d03bd 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java @@ -381,7 +381,8 @@ public class SettingsFragment extends PreferenceFragment Toast.makeText(getActivity(), getString(R.string.config_imported_successful), Toast.LENGTH_SHORT).show(); - mSyncthingService.getApi().requireRestart(getActivity()); + // No need to restart, as we shutdown to import the config, and + // then have to start Syncthing again. } else { Toast.makeText(getActivity(), getString(R.string.config_import_failed, diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java index d891ef37..eabc2745 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java @@ -136,7 +136,7 @@ public class SyncthingRunnable implements Runnable { lInfo.join(); lWarn.join(); - // Restart if that was requested. + // Restart if that was requested via Rest API call. if (ret == 3) { Log.i(TAG, "Restarting syncthing"); mContext.startService(new Intent(mContext, SyncthingService.class) diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java index 808d2959..0cfd8a16 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java @@ -606,6 +606,8 @@ public class SyncthingService extends Service implements * @return True if the import was successful, false otherwise (eg if files aren't found). */ public boolean importConfig() { + mCurrentState = State.DISABLED; + shutdown(); File config = new File(EXPORT_PATH, ConfigXml.CONFIG_FILE); File privateKey = new File(EXPORT_PATH, PRIVATE_KEY_FILE); File publicKey = new File(EXPORT_PATH, PUBLIC_KEY_FILE); @@ -615,6 +617,8 @@ public class SyncthingService extends Service implements copyFile(config, new File(getFilesDir(), ConfigXml.CONFIG_FILE)); copyFile(privateKey, new File(getFilesDir(), PRIVATE_KEY_FILE)); copyFile(publicKey, new File(getFilesDir(), PUBLIC_KEY_FILE)); + mCurrentState = State.INIT; + updateState(); return true; }