diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java index b27771e3d03..bf6b314b414 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java @@ -15,6 +15,7 @@ package org.eclipse.core.internal.localstore; import java.io.*; +import java.nio.file.AtomicMoveNotSupportedException; import java.nio.file.Files; import java.nio.file.StandardCopyOption; @@ -82,8 +83,13 @@ protected void commit() throws IOException { if (!temp.exists()) { return; } - Files.copy(temp.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); - temp.delete(); + try { + // a rename does not rewrite the bytes and never leaves a partially written target + Files.move(temp.toPath(), target.toPath(), StandardCopyOption.ATOMIC_MOVE); + } catch (AtomicMoveNotSupportedException e) { + Files.copy(temp.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); + temp.delete(); + } } protected void createTempFile(String tempPath) {