Skip to content

Commit 57f02f3

Browse files
authored
Dont flush settings on exit after import (#1179)
Fixes bug when importing settings zip that would have the new settings be over written, and would not actually update
1 parent 580bbb4 commit 57f02f3

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

photon-core/src/main/java/org/photonvision/common/configuration/ConfigManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public class ConfigManager {
5050
private final Thread settingsSaveThread;
5151
private long saveRequestTimestamp = -1;
5252

53+
// special case flag to disable flushing settings to disk at shutdown. Avoids the jvm shutdown
54+
// hook overwriting the settings we just uploaded
55+
private boolean flushOnShutdown = true;
56+
5357
enum ConfigSaveStrategy {
5458
SQL,
5559
LEGACY,
@@ -303,4 +307,19 @@ public File getModelsDirectory() {
303307
if (!ret.exists()) ret.mkdirs();
304308
return ret;
305309
}
310+
311+
/**
312+
* Disable flushing settings to disk as part of our JVM exit hook. Used to prevent uploading all
313+
* settings from getting its new configs overwritten at program exit and before theyre all loaded.
314+
*/
315+
public void disableFlushOnShutdown() {
316+
this.flushOnShutdown = false;
317+
}
318+
319+
public void onJvmExit() {
320+
if (flushOnShutdown) {
321+
logger.info("Force-flushing settings...");
322+
saveToDisk();
323+
}
324+
}
306325
}

photon-core/src/main/java/org/photonvision/common/hardware/HardwareManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ private void onJvmExit() {
145145
logger.info("Shutting down LEDs...");
146146
if (visionLED != null) visionLED.setState(false);
147147

148-
logger.info("Force-flushing settings...");
149-
ConfigManager.getInstance().saveToDisk();
148+
ConfigManager.getInstance().onJvmExit();
150149
}
151150

152151
public boolean restartDevice() {

photon-server/src/main/java/org/photonvision/server/RequestHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static void onSettingsImportRequest(Context ctx) {
9494
ctx.status(200);
9595
ctx.result("Successfully saved the uploaded settings zip, rebooting...");
9696
logger.info("Successfully saved the uploaded settings zip, rebooting...");
97+
ConfigManager.getInstance().disableFlushOnShutdown();
9798
restartProgram();
9899
} else {
99100
ctx.status(500);

0 commit comments

Comments
 (0)