git://git.nikiroo.be
/
nikiroo-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
05c4f40
)
Fix TemporaryFiles.close() is not indempotent
author
Niki
<david.roulet@uclouvain.be>
Mon, 15 Apr 2019 08:03:15 +0000
(10:03 +0200)
committer
Niki
<david.roulet@uclouvain.be>
Mon, 15 Apr 2019 08:03:15 +0000
(10:03 +0200)
src/be/nikiroo/utils/TempFiles.java
patch
|
blob
|
blame
|
history
diff --git
a/src/be/nikiroo/utils/TempFiles.java
b/src/be/nikiroo/utils/TempFiles.java
index 865fbce765c474b30e86362ae36a2343e745eb7e..b54f0bc3e7ae5642cb9e3c8a135ac656eed4dee9 100644
(file)
--- a/
src/be/nikiroo/utils/TempFiles.java
+++ b/
src/be/nikiroo/utils/TempFiles.java
@@
-110,8
+110,8
@@
public class TempFiles implements Closeable {
if (!test.exists()) {
test.createNewFile();
if (!test.exists()) {
if (!test.exists()) {
test.createNewFile();
if (!test.exists()) {
- throw new IOException(
"Cannot create temporary file: "
- + test);
+ throw new IOException(
+
"Cannot create temporary file: "
+ test);
}
test.deleteOnExit();
}
test.deleteOnExit();
@@
-164,9
+164,16
@@
public class TempFiles implements Closeable {
@Override
public synchronized void close() throws IOException {
@Override
public synchronized void close() throws IOException {
- IOUtils.deltree(root); // NO exception here
- root.getParentFile().delete(); // only if empty
- root = null;
+ File root = this.root;
+ this.root = null;
+
+ if (root != null) {
+ IOUtils.deltree(root);
+
+ // Since we allocate temp directories from a base point,
+ // try and remove that base point
+ root.getParentFile().delete(); // (only works if empty)
+ }
}
@Override
}
@Override