altoslib: Make sure .eeprom download file is flushed on exception
authorKeith Packard <keithp@keithp.com>
Mon, 21 Sep 2015 05:25:49 +0000 (06:25 +0100)
committerKeith Packard <keithp@keithp.com>
Tue, 13 Oct 2015 20:54:28 +0000 (13:54 -0700)
Flush and close the eeprom file even if an exception occurs to make
sure that contents of the file aren't lost.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosEepromDownload.java

index 5e035dbc008ddb4c12b23311ca940ef25e69efd3..c4ddb0e7472c851d8d9e54673c383a98f33dcc4e 100644 (file)
@@ -147,7 +147,6 @@ public class AltosEepromDownload implements Runnable {
 
                /* Reset per-capture variables */
                want_file = false;
-               eeprom_file = null;
                eeprom_pending = new LinkedList<String>();
 
                /* Set serial number in the monitor dialog window */
@@ -185,10 +184,6 @@ public class AltosEepromDownload implements Runnable {
                                          block - log.start_block);
                }
                CheckFile(true);
-               if (eeprom_file != null) {
-                       eeprom_file.flush();
-                       eeprom_file.close();
-               }
        }
 
        public void run () {
@@ -201,11 +196,16 @@ public class AltosEepromDownload implements Runnable {
                                parse_exception = null;
                                if (log.selected) {
                                        monitor.reset();
+                                       eeprom_file = null;
                                        try {
                                                CaptureLog(log);
                                        } catch (ParseException e) {
                                                parse_exception = e;
                                        }
+                                       if (eeprom_file != null) {
+                                               eeprom_file.flush();
+                                               eeprom_file.close();
+                                       }
                                }
                                if (parse_exception != null) {
                                        failed = true;