Fix can't del tmp file in windows
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.
@@ -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 {
+ 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;
