From 4378236d47aca3e32717ef1b44253aa70195683d Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Tue, 28 Nov 2023 15:34:22 +0100 Subject: [PATCH] fix regression with FileStream --- .../main/java/lucee/runtime/functions/file/FileAppend.java | 4 +++- .../src/main/java/lucee/runtime/functions/file/FileWrite.java | 2 +- .../main/java/lucee/runtime/functions/file/FileWriteLine.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/lucee/runtime/functions/file/FileAppend.java b/core/src/main/java/lucee/runtime/functions/file/FileAppend.java index 2448e83857..020e3c12c4 100644 --- a/core/src/main/java/lucee/runtime/functions/file/FileAppend.java +++ b/core/src/main/java/lucee/runtime/functions/file/FileAppend.java @@ -37,6 +37,7 @@ public static String call(PageContext pc, Object file, Object data) throws PageE public static String call(PageContext pc, Object file, Object data, String charset) throws PageException { FileStreamWrapper fsw = null; + boolean close = false; if (StringUtil.isEmpty(charset, true)) charset = ((PageContextImpl) pc).getResourceCharset().name(); Resource res = null; try { @@ -44,6 +45,7 @@ public static String call(PageContext pc, Object file, Object data, String chars fsw = (FileStreamWrapper) file; } else { + close = true; res = Caster.toResource(pc, file, false); pc.getConfig().getSecurityManager().checkFileLocation(res); fsw = new FileStreamWrapperWrite(res, charset, true, false); @@ -54,7 +56,7 @@ public static String call(PageContext pc, Object file, Object data, String chars throw Caster.toPageException(e); } finally { - IOUtil.closeEL(fsw); + if (close) IOUtil.closeEL(fsw); if (res != null) PageSourcePool.flush(pc, res); else PageSourcePool.flush(pc, file); } diff --git a/core/src/main/java/lucee/runtime/functions/file/FileWrite.java b/core/src/main/java/lucee/runtime/functions/file/FileWrite.java index de1017a947..444fdd5f04 100755 --- a/core/src/main/java/lucee/runtime/functions/file/FileWrite.java +++ b/core/src/main/java/lucee/runtime/functions/file/FileWrite.java @@ -60,7 +60,7 @@ public static String call(PageContext pc, Object obj, Object data, String charse throw Caster.toPageException(e); } finally { - IOUtil.closeEL(fsw); + if (close) IOUtil.closeEL(fsw); if (fsw != null) PageSourcePool.flush(pc, fsw); } diff --git a/core/src/main/java/lucee/runtime/functions/file/FileWriteLine.java b/core/src/main/java/lucee/runtime/functions/file/FileWriteLine.java index 1be26c9154..c25e6a5d20 100755 --- a/core/src/main/java/lucee/runtime/functions/file/FileWriteLine.java +++ b/core/src/main/java/lucee/runtime/functions/file/FileWriteLine.java @@ -20,6 +20,7 @@ import java.io.IOException; +import lucee.commons.io.IOUtil; import lucee.commons.io.SystemUtil; import lucee.commons.io.res.Resource; import lucee.runtime.PageContext; @@ -46,7 +47,7 @@ public static String call(PageContext pc, Object obj, String text) throws PageEx fsw.write(text + SystemUtil.lineSeparator()); } finally { - if (close && fsw != null) fsw.close(); + if (close) IOUtil.closeEL(fsw); } }