Skip to content

Commit

Permalink
allow specifying a file extension for getTempFile LDEV-2331 (#1148)
Browse files Browse the repository at this point in the history
* Added a fix for LDEV-2331

* Update GetTempFile.java
  • Loading branch information
cfmitrah authored Apr 1, 2021
1 parent 7cf1711 commit 6491aee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/resource/fld/core-base.fld
Original file line number Diff line number Diff line change
Expand Up @@ -6582,6 +6582,14 @@ if this attribute is not provided all types are returned.</description>
<required>Yes</required>
<description>Prefix of a temporary file to create in the dir directory</description>
</argument>
<argument>
<name>extension</name>
<alias>ext</alias>
<type>string</type>
<required>No</required>
<Default>tmp</Default>
<description>Creates temporary files with user defined extension, default is .tmp</description>
</argument>
<return>
<type>string</type>
</return>
Expand Down

0 comments on commit 6491aee

Please sign in to comment.