From 6491aee191e9c1f5246d0a27eb48a3777e19dfa4 Mon Sep 17 00:00:00 2001 From: Saravanamuthu Aka CF Mitrah Date: Thu, 1 Apr 2021 21:05:16 +0530 Subject: [PATCH] allow specifying a file extension for getTempFile LDEV-2331 (#1148) * Added a fix for LDEV-2331 * Update GetTempFile.java --- .../java/lucee/runtime/functions/system/GetTempFile.java | 8 +++++++- core/src/main/java/resource/fld/core-base.fld | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/lucee/runtime/functions/system/GetTempFile.java b/core/src/main/java/lucee/runtime/functions/system/GetTempFile.java index ef7108ed5d..36081ea295 100644 --- a/core/src/main/java/lucee/runtime/functions/system/GetTempFile.java +++ b/core/src/main/java/lucee/runtime/functions/system/GetTempFile.java @@ -33,12 +33,18 @@ public final class GetTempFile implements Function { public static String call(PageContext pc, String strDir, String prefix) throws PageException { + return call(pc, strDir, prefix, ".tmp"); + } + + public static String call(PageContext pc, String strDir, String prefix, String extension) throws PageException { Resource dir = ResourceUtil.toResourceExisting(pc, strDir); pc.getConfig().getSecurityManager().checkFileLocation(dir); if (!dir.isDirectory()) throw new ExpressionException("[" + strDir + "] is not a directory"); int count = 1; Resource file; - while ((file = dir.getRealResource(prefix + pc.getId() + count + ".tmp")).exists()) { + if (extension.trim().isEmpty() == true) { extension = ".tmp"; } + if (extension.charAt(0) != '.') { extension = "." + extension; } + while ((file = dir.getRealResource(prefix + pc.getId() + count + extension)).exists()) { count++; } try { diff --git a/core/src/main/java/resource/fld/core-base.fld b/core/src/main/java/resource/fld/core-base.fld index 28e132d30d..4b921dd5a6 100755 --- a/core/src/main/java/resource/fld/core-base.fld +++ b/core/src/main/java/resource/fld/core-base.fld @@ -6582,6 +6582,14 @@ if this attribute is not provided all types are returned. Yes Prefix of a temporary file to create in the dir directory + + extension + ext + string + No + tmp + Creates temporary files with user defined extension, default is .tmp + string