diff --git a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java index dc8b9289d0f..9af22324fd9 100644 --- a/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/core/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -897,17 +897,20 @@ public final class NodeEnvironment extends AbstractComponent implements Closeabl for (NodePath nodePath : nodePaths) { assert Files.isDirectory(nodePath.path) : nodePath.path + " is not a directory"; final Path src = nodePath.path.resolve("__es__.tmp"); - Files.createFile(src); final Path target = nodePath.path.resolve("__es__.final"); try { + Files.createFile(src); Files.move(src, target, StandardCopyOption.ATOMIC_MOVE); } catch (AtomicMoveNotSupportedException ex) { throw new IllegalStateException("atomic_move is not supported by the filesystem on path [" + nodePath.path + "] atomic_move is required for elasticsearch to work correctly.", ex); } finally { - Files.deleteIfExists(src); - Files.deleteIfExists(target); + try { + Files.deleteIfExists(src); + } finally { + Files.deleteIfExists(target); + } } } }