diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-12-28 12:12:01 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-12-28 12:12:01 +0000 |
commit | 57852e0c7d82eb0b547b1550490e72962ba0715d (patch) | |
tree | bb3d8fc4a963dadcc1a784d00bd759300c36b392 /poi/src/main | |
parent | 70dc07dd3b6a6bc7c85546f8a1ba30e9851b1e83 (diff) | |
download | poi-57852e0c7d82eb0b547b1550490e72962ba0715d.tar.gz poi-57852e0c7d82eb0b547b1550490e72962ba0715d.zip |
[bug-65772] stop using deleteOnExit in DefaultTempFileCreationStrategy
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896473 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src/main')
-rw-r--r-- | poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java | 5 | ||||
-rw-r--r-- | poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java | 16 |
2 files changed, 11 insertions, 10 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 ffdec5ab5d..7f174b2381 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 @@ -71,7 +71,6 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { this.plainByteFlags = new SparseBitSet(cs); this.chunkBits = Integer.bitCount(cs-1); this.fileOut = TempFile.createTempFile("encrypted_package", "crypt"); - this.fileOut.deleteOnExit(); this.out = new FileOutputStream(fileOut); this.dir = dir; this.cipher = initCipherForBlock(null, 0, false); @@ -266,6 +265,10 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { } } catch (GeneralSecurityException e) { throw new IOException(e); + } finally { + if (fileOut != null) { + fileOut.delete(); + } } } diff --git a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java index f2e51d48ab..bbfb03e9ab 100644 --- a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java +++ b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java @@ -26,7 +26,7 @@ import java.io.IOException; * Default implementation of the {@link TempFileCreationStrategy} used by {@link TempFile}: * Files are collected into one directory and by default are deleted on exit from the VM. * Files may be manually deleted by user prior to JVM exit. - * Files can be kept by defining the system property {@link #KEEP_FILES}. + * Files can be kept by defining the system property {@link #DELETE_FILES_ON_EXIT}. * * Each file is registered for deletion with the JVM and the temporary directory is not deleted * after the JVM exits. Files that are created in the poifiles directory outside @@ -37,8 +37,8 @@ import java.io.IOException; public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy { public static final String POIFILES = "poifiles"; - /** To keep files after JVM exit, set the <code>-Dpoi.keep.tmp.files</code> JVM property */ - public static final String KEEP_FILES = "poi.keep.tmp.files"; + /** To use files.deleteOnExit after clean JVM exit, set the <code>-Dpoi.delete.tmp.files.on.exit</code> JVM property */ + public static final String DELETE_FILES_ON_EXIT = "poi.delete.tmp.files.on.exit"; /** The directory where the temporary files will be created (<code>null</code> to use the default directory). */ private File dir; @@ -105,8 +105,8 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy // Generate a unique new filename File newFile = File.createTempFile(prefix, suffix, dir); - // Set the delete on exit flag, unless explicitly disabled - if (System.getProperty(KEEP_FILES) == null) { + // Set the delete on exit flag, but only when explicitly disabled + if (System.getProperty(DELETE_FILES_ON_EXIT) != null) { newFile.deleteOnExit(); } @@ -126,10 +126,8 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy File newDirectory = new File(dir, prefix + Long.toString(n)); createTempDirectory(newDirectory); - // Set the delete on exit flag, unless explicitly disabled - if (System.getProperty(KEEP_FILES) == null) { - newDirectory.deleteOnExit(); - } + //this method appears to be only used in tests, so it is probably ok to use deleteOnExit + newDirectory.deleteOnExit(); // All done return newDirectory; |