You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2020/09/09 13:20:25 UTC
[tika] branch main updated: Fix can't del tmp file in windows (#332)
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new 4ccdf46 Fix can't del tmp file in windows (#332)
4ccdf46 is described below
commit 4ccdf460f62764eb3cffa8d27e7482e3c48407a6
Author: Lee <55...@users.noreply.github.com>
AuthorDate: Wed Sep 9 21:20:15 2020 +0800
Fix can't del tmp file in windows (#332)
TestCase org.apache.tika.image.HeifParserTest.testSimple fail in windows
because TemporaryResources.close() fail to delete tmp file.
This is a fix for it by set tmp file delete on exit if current delete fail.
---
.../src/main/java/org/apache/tika/io/TemporaryResources.java | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java b/tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java
index 2dad5bd..6a1e1b6 100644
--- a/tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java
+++ b/tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java
@@ -24,6 +24,8 @@ import java.nio.file.Path;
import java.util.LinkedList;
import org.apache.tika.exception.TikaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility class for tracking and ultimately closing or otherwise disposing
@@ -35,6 +37,8 @@ import org.apache.tika.exception.TikaException;
*/
public class TemporaryResources implements Closeable {
+ private static final Logger LOG = LoggerFactory.getLogger(TemporaryResources.class);
+
/**
* Tracked resources in LIFO order.
*/
@@ -81,7 +85,13 @@ public class TemporaryResources implements Closeable {
: Files.createTempFile(tempFileDir, "apache-tika-", ".tmp");
addResource(new Closeable() {
public void close() throws IOException {
- Files.delete(path);
+ try {
+ Files.delete(path);
+ } catch (IOException e) {
+ // delete when exit if current delete fail
+ LOG.warn("delete tmp file fail, will delete it on exit");
+ path.toFile().deleteOnExit();
+ }
}
});
return path;