changeset 12255:351dac0d87de octave-forge

Overhauled detection logic for how file should be closed; no more lingering file locks now
author prnienhuis
date Sun, 29 Dec 2013 22:36:28 +0000
parents e9ce88dd5779
children c226af31d4ad
files main/io/inst/private/__OXS_spsh_close__.m
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/main/io/inst/private/__OXS_spsh_close__.m	Sun Dec 29 22:35:05 2013 +0000
+++ b/main/io/inst/private/__OXS_spsh_close__.m	Sun Dec 29 22:36:28 2013 +0000
@@ -21,7 +21,9 @@
 ## Updates:
 ## 2012-10-24 Style fixes
 ## 2013-01-20 Adapted to ML-compatible Java calls
-## 2013-12-06 Updated copyright string
+## 2013-12-06 Updated copyright string
+## 2013-12-28 Style fixes
+##     ''     Moved wb close statement down to always unlock file
 
 function [ xls ] = __OXS_spsh_close__ (xls)
 
@@ -32,20 +34,17 @@
         fname = xls.filename;
       endif
       try
-        xlsout = javaObject ("java.io.FileOutputStream", fname);
-        bufout = javaObject ("java.io.BufferedOutputStream", xlsout);
-        if (xls.changed == 2) printf ("Saving file %s...\n", fname); endif
-        xls.workbook.writeBytes (bufout);
-        xls.workbook.close ();
-        bufout.flush ();
-        bufout.close ();
+        if (xls.changed == 2)
+          printf ("Saving file %s...\n", fname);
+        endif
+        xlsout = javaObject ("java.io.FileOutputStream", fname);
+        xls.workbook.write (xlsout);
         xlsout.close ();
         xls.changed = 0;
       catch
-##      xlsout.close ();
+        warning ("__OXS_spsh_close__: error trying to close OXS file ptr");
       end_try_catch
-    else
-      xls.workbook.close ();
     endif
+    xls.workbook.close ();
 
 endfunction