changeset 23189:0c9195baea1a stable

print.m: fix regression with -append option (bug #50318) * print.m: do not delete file if it already existed and open it in "a" mode so that it is not truncated
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Thu, 16 Feb 2017 10:08:39 +0100
parents 41a01755a7b9
children d222db279c21
files scripts/plot/util/print.m
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/print.m	Tue Feb 14 16:00:11 2017 -0800
+++ b/scripts/plot/util/print.m	Thu Feb 16 10:08:39 2017 +0100
@@ -319,12 +319,16 @@
     error ("print: directory %s does not exist", folder);
   endif
 
-  fid = fopen (opts.name, "w+");
+  ## Check the requested file is writable
+  do_unlink = (exist (opts.name, "file") != 2);
+  fid = fopen (opts.name, "a");
   if (fid == -1)
     error ("print: cannot open file %s for writing", opts.name);
   endif
   fclose (fid);
-  unlink (opts.name);
+  if (do_unlink)
+    unlink (opts.name);
+  endif
 
   opts.pstoedit_cmd = @pstoedit;
   opts.fig2dev_cmd = @fig2dev;