File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
photon-core/src/main/java/org/photonvision/common
photon-server/src/main/java/org/photonvision/server Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,10 @@ public class ConfigManager {
50
50
private final Thread settingsSaveThread ;
51
51
private long saveRequestTimestamp = -1 ;
52
52
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
+
53
57
enum ConfigSaveStrategy {
54
58
SQL ,
55
59
LEGACY ,
@@ -303,4 +307,19 @@ public File getModelsDirectory() {
303
307
if (!ret .exists ()) ret .mkdirs ();
304
308
return ret ;
305
309
}
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
+ }
306
325
}
Original file line number Diff line number Diff line change @@ -145,8 +145,7 @@ private void onJvmExit() {
145
145
logger .info ("Shutting down LEDs..." );
146
146
if (visionLED != null ) visionLED .setState (false );
147
147
148
- logger .info ("Force-flushing settings..." );
149
- ConfigManager .getInstance ().saveToDisk ();
148
+ ConfigManager .getInstance ().onJvmExit ();
150
149
}
151
150
152
151
public boolean restartDevice () {
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ public static void onSettingsImportRequest(Context ctx) {
94
94
ctx .status (200 );
95
95
ctx .result ("Successfully saved the uploaded settings zip, rebooting..." );
96
96
logger .info ("Successfully saved the uploaded settings zip, rebooting..." );
97
+ ConfigManager .getInstance ().disableFlushOnShutdown ();
97
98
restartProgram ();
98
99
} else {
99
100
ctx .status (500 );
You can’t perform that action at this time.
0 commit comments