From dd137fc7030c46c03810c013d5dfb16577ae4986 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Mon, 9 Oct 2023 08:52:12 +0200 Subject: [PATCH] Ensure target exists calling FileSystemResourceManager.write() #103 The FileSystemResourceManager.write() method assumes the passed target to exist. Some operations in the File class do not properly ensure that. They check the file existence before starting a workspace operation, which allows some other operation, such as a refresh, to remove the file from the workspace between the check and the start of the operation. With this change, the existence check in the File class is performed after starting a workspace operation, such that no other operation is able to remove the file concurrently and make the write operation file. Contributes to https://github.com/eclipse-platform/eclipse.platform/issues/103. --- .../src/org/eclipse/core/internal/resources/File.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java index 32b159fe05d..e0c5d4dff96 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java @@ -70,8 +70,8 @@ public void appendContents(InputStream content, int updateFlags, IProgressMonito try { workspace.prepareOperation(rule, newChild); ResourceInfo info = getResourceInfo(false, false); - checkAccessible(getFlags(info)); workspace.beginOperation(true); + checkAccessible(getFlags(info)); IFileInfo fileInfo = getStore().fetchInfo(); internalSetContents(content, fileInfo, updateFlags, true, subMonitor.newChild(99)); } catch (OperationCanceledException e) { @@ -354,8 +354,8 @@ public void setContents(InputStream content, int updateFlags, IProgressMonitor m try { workspace.prepareOperation(rule, newChild); ResourceInfo info = getResourceInfo(false, false); - checkAccessible(getFlags(info)); workspace.beginOperation(true); + checkAccessible(getFlags(info)); IFileInfo fileInfo = getStore().fetchInfo(); internalSetContents(content, fileInfo, updateFlags, false, subMonitor.newChild(99)); } catch (OperationCanceledException e) {