mirror of
https://github.com/apache/poi.git
synced 2025-02-08 11:04:53 +00:00
[bug-65772] stop using deleteOnExit in DefaultTempFileCreationStrategy
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
70dc07dd3b
commit
57852e0c7d
@ -36,6 +36,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
|||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.apache.poi.util.Removal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides handy methods to work with OOXML packages
|
* Provides handy methods to work with OOXML packages
|
||||||
@ -71,7 +72,10 @@ public final class PackageHelper {
|
|||||||
* @param pkg the package to clone
|
* @param pkg the package to clone
|
||||||
* @param file the destination file
|
* @param file the destination file
|
||||||
* @return the cloned package
|
* @return the cloned package
|
||||||
|
* @deprecated this method is not used internally and creates temp files that are not well handled
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@Removal(version = "6.0.0")
|
||||||
public static OPCPackage clone(OPCPackage pkg, File file) throws OpenXML4JException, IOException {
|
public static OPCPackage clone(OPCPackage pkg, File file) throws OpenXML4JException, IOException {
|
||||||
|
|
||||||
String path = file.getAbsolutePath();
|
String path = file.getAbsolutePath();
|
||||||
|
@ -71,7 +71,6 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
|
|||||||
this.plainByteFlags = new SparseBitSet(cs);
|
this.plainByteFlags = new SparseBitSet(cs);
|
||||||
this.chunkBits = Integer.bitCount(cs-1);
|
this.chunkBits = Integer.bitCount(cs-1);
|
||||||
this.fileOut = TempFile.createTempFile("encrypted_package", "crypt");
|
this.fileOut = TempFile.createTempFile("encrypted_package", "crypt");
|
||||||
this.fileOut.deleteOnExit();
|
|
||||||
this.out = new FileOutputStream(fileOut);
|
this.out = new FileOutputStream(fileOut);
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
this.cipher = initCipherForBlock(null, 0, false);
|
this.cipher = initCipherForBlock(null, 0, false);
|
||||||
@ -266,6 +265,10 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
|
} finally {
|
||||||
|
if (fileOut != null) {
|
||||||
|
fileOut.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import java.io.IOException;
|
|||||||
* Default implementation of the {@link TempFileCreationStrategy} used by {@link TempFile}:
|
* 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 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 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
|
* 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
|
* 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 class DefaultTempFileCreationStrategy implements TempFileCreationStrategy {
|
||||||
public static final String POIFILES = "poifiles";
|
public static final String POIFILES = "poifiles";
|
||||||
|
|
||||||
/** To keep files after JVM exit, set the <code>-Dpoi.keep.tmp.files</code> JVM property */
|
/** To use files.deleteOnExit after clean JVM exit, set the <code>-Dpoi.delete.tmp.files.on.exit</code> JVM property */
|
||||||
public static final String KEEP_FILES = "poi.keep.tmp.files";
|
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). */
|
/** The directory where the temporary files will be created (<code>null</code> to use the default directory). */
|
||||||
private File dir;
|
private File dir;
|
||||||
@ -105,8 +105,8 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
|
|||||||
// Generate a unique new filename
|
// Generate a unique new filename
|
||||||
File newFile = File.createTempFile(prefix, suffix, dir);
|
File newFile = File.createTempFile(prefix, suffix, dir);
|
||||||
|
|
||||||
// Set the delete on exit flag, unless explicitly disabled
|
// Set the delete on exit flag, but only when explicitly disabled
|
||||||
if (System.getProperty(KEEP_FILES) == null) {
|
if (System.getProperty(DELETE_FILES_ON_EXIT) != null) {
|
||||||
newFile.deleteOnExit();
|
newFile.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,10 +126,8 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
|
|||||||
File newDirectory = new File(dir, prefix + Long.toString(n));
|
File newDirectory = new File(dir, prefix + Long.toString(n));
|
||||||
createTempDirectory(newDirectory);
|
createTempDirectory(newDirectory);
|
||||||
|
|
||||||
// Set the delete on exit flag, unless explicitly disabled
|
//this method appears to be only used in tests, so it is probably ok to use deleteOnExit
|
||||||
if (System.getProperty(KEEP_FILES) == null) {
|
|
||||||
newDirectory.deleteOnExit();
|
newDirectory.deleteOnExit();
|
||||||
}
|
|
||||||
|
|
||||||
// All done
|
// All done
|
||||||
return newDirectory;
|
return newDirectory;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user