summaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-12-28 12:36:51 +0000
committerPJ Fanning <fanningpj@apache.org>2021-12-28 12:36:51 +0000
commitd442ea645c543fd86a41ca9a88f96b8e0c0aae4d (patch)
tree8feaa0264ffafb7276a6fb6265cd1a7b4a436630 /poi
parent57852e0c7d82eb0b547b1550490e72962ba0715d (diff)
downloadpoi-d442ea645c543fd86a41ca9a88f96b8e0c0aae4d.tar.gz
poi-d442ea645c543fd86a41ca9a88f96b8e0c0aae4d.zip
[bug-65772] stop using deleteOnExit in DefaultTempFileCreationStrategy
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896474 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java11
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java9
3 files changed, 19 insertions, 5 deletions
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
index 7f174b2381..d4ae39bf47 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
@@ -267,7 +267,9 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
throw new IOException(e);
} finally {
if (fileOut != null) {
- fileOut.delete();
+ if (!fileOut.delete()) {
+ //ignore
+ }
}
}
}
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
index d5fbc712f8..0e1beaeb11 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
@@ -131,9 +131,10 @@ public class StandardEncryptor extends Encryptor {
protected long countBytes;
protected final File fileOut;
protected final DirectoryNode dir;
+ protected final boolean deleteFile;
@SuppressWarnings({"resource", "squid:S2095"})
- private StandardCipherOutputStream(DirectoryNode dir, File fileOut) throws IOException {
+ private StandardCipherOutputStream(DirectoryNode dir, File fileOut, boolean deleteFile) throws IOException {
// although not documented, we need the same padding as with agile encryption
// and instead of calculating the missing bytes for the block size ourselves
// we leave it up to the CipherOutputStream, which generates/saves them on close()
@@ -147,12 +148,13 @@ public class StandardEncryptor extends Encryptor {
super(
new CipherOutputStream(new FileOutputStream(fileOut), getCipher(getSecretKey(), "PKCS5Padding"))
);
+ this.deleteFile = deleteFile;
this.fileOut = fileOut;
this.dir = dir;
}
protected StandardCipherOutputStream(DirectoryNode dir) throws IOException {
- this(dir, TempFile.createTempFile("encrypted_package", "crypt"));
+ this(dir, TempFile.createTempFile("encrypted_package", "crypt"), true);
}
@Override
@@ -172,6 +174,11 @@ public class StandardEncryptor extends Encryptor {
// the CipherOutputStream adds the padding bytes on close()
super.close();
writeToPOIFS();
+ if (deleteFile && fileOut != null) {
+ if (!fileOut.delete()) {
+ //ignore
+ }
+ }
}
void writeToPOIFS() throws IOException {
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
index 0155ab0fe1..3e7c1ab2a2 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
@@ -618,7 +618,12 @@ public final class ExcelFileFormatDocFunctionExtractor {
// }
File tempEFFDocFile = downloadSourceFile();
- processFile(tempEFFDocFile, outFile);
- tempEFFDocFile.delete();
+ try {
+ processFile(tempEFFDocFile, outFile);
+ } finally {
+ if (!tempEFFDocFile.delete()) {
+ //ignore
+ }
+ }
}
}