Skip to content

Commit

Permalink
Ensure target exists calling FileSystemResourceManager.write() #103
Browse files Browse the repository at this point in the history
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
#103.
  • Loading branch information
HeikoKlare committed Oct 9, 2023
1 parent 5f450df commit dd137fc
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dd137fc

Please sign in to comment.