Skip to content

Commit

Permalink
Dont flush settings on exit after import (#1179)
Browse files Browse the repository at this point in the history
Fixes bug when importing settings zip that would have the new settings be over written, and would not actually update
  • Loading branch information
mcm001 authored Jan 21, 2024
1 parent 580bbb4 commit 57f02f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class ConfigManager {
private final Thread settingsSaveThread;
private long saveRequestTimestamp = -1;

// special case flag to disable flushing settings to disk at shutdown. Avoids the jvm shutdown
// hook overwriting the settings we just uploaded
private boolean flushOnShutdown = true;

enum ConfigSaveStrategy {
SQL,
LEGACY,
Expand Down Expand Up @@ -303,4 +307,19 @@ public File getModelsDirectory() {
if (!ret.exists()) ret.mkdirs();
return ret;
}

/**
* Disable flushing settings to disk as part of our JVM exit hook. Used to prevent uploading all
* settings from getting its new configs overwritten at program exit and before theyre all loaded.
*/
public void disableFlushOnShutdown() {
this.flushOnShutdown = false;
}

public void onJvmExit() {
if (flushOnShutdown) {
logger.info("Force-flushing settings...");
saveToDisk();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ private void onJvmExit() {
logger.info("Shutting down LEDs...");
if (visionLED != null) visionLED.setState(false);

logger.info("Force-flushing settings...");
ConfigManager.getInstance().saveToDisk();
ConfigManager.getInstance().onJvmExit();
}

public boolean restartDevice() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static void onSettingsImportRequest(Context ctx) {
ctx.status(200);
ctx.result("Successfully saved the uploaded settings zip, rebooting...");
logger.info("Successfully saved the uploaded settings zip, rebooting...");
ConfigManager.getInstance().disableFlushOnShutdown();
restartProgram();
} else {
ctx.status(500);
Expand Down

0 comments on commit 57f02f3

Please sign in to comment.