Skip to content

Commit 6bfdd8c

Browse files
committed
Avoid duplicated IFileInfo fetches when creating resources
1 parent 93a2f4b commit 6bfdd8c

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -557,15 +557,6 @@ public IHistoryStore getHistoryStore() {
557557
return _historyStore;
558558
}
559559

560-
/**
561-
* Returns the real name of the resource on disk. Returns null if no local
562-
* file exists by that name. This is useful when dealing with
563-
* case insensitive file systems.
564-
*/
565-
public String getLocalName(IFileStore target) {
566-
return target.fetchInfo().getName();
567-
}
568-
569560
protected IPath getProjectDefaultLocation(IProject project) {
570561
return workspace.getRoot().getLocation().append(project.getFullPath());
571562
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.io.Reader;
24+
import java.nio.file.Path;
2425
import java.util.ArrayList;
2526
import java.util.List;
2627
import java.util.Map.Entry;
@@ -221,25 +222,24 @@ void checkCreatable() throws CoreException {
221222

222223
IFileInfo create(int updateFlags, IProgressMonitor subMonitor, IFileStore store)
223224
throws CoreException, ResourceException {
224-
String message;
225225
IFileInfo localInfo;
226226
if (BitMask.isSet(updateFlags, IResource.FORCE)) {
227-
// Assume the file does not exist - otherwise implementation fails later
227+
// Assume the file does not exist - otherwise implementation fails later
228228
// during actual write
229229
localInfo = new FileInfo(getName()); // with exists==false
230230
} else {
231-
localInfo=store.fetchInfo();
231+
localInfo = store.fetchInfo();
232232
if (localInfo.exists()) {
233233
// return an appropriate error message for case variant collisions
234234
if (!Workspace.caseSensitive) {
235-
String name = getLocalManager().getLocalName(store);
235+
String name = localInfo.getName();
236236
if (name != null && !localInfo.getName().equals(name)) {
237-
message = NLS.bind(Messages.resources_existsLocalDifferentCase,
238-
IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString());
237+
String message = NLS.bind(Messages.resources_existsLocalDifferentCase,
238+
Path.of(store.toString()).resolveSibling(name));
239239
throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
240240
}
241241
}
242-
message = NLS.bind(Messages.resources_fileExists, store.toString());
242+
String message = NLS.bind(Messages.resources_fileExists, store.toString());
243243
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), message, null);
244244
}
245245
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Folder.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515
package org.eclipse.core.internal.resources;
1616

1717
import java.net.URI;
18+
import java.nio.file.Path;
1819
import org.eclipse.core.filesystem.IFileInfo;
1920
import org.eclipse.core.filesystem.IFileStore;
2021
import org.eclipse.core.internal.utils.Messages;
@@ -47,9 +48,10 @@ protected void assertCreateRequirements(IFileStore store, IFileInfo localInfo, i
4748
if (!force && localInfo.exists()) {
4849
//return an appropriate error message for case variant collisions
4950
if (!Workspace.caseSensitive) {
50-
String name = getLocalManager().getLocalName(store);
51+
String name = localInfo.getName();
5152
if (name != null && !store.getName().equals(name)) {
52-
String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString());
53+
String msg = NLS.bind(Messages.resources_existsLocalDifferentCase,
54+
Path.of(store.toString()).resolveSibling(name));
5355
throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null);
5456
}
5557
}
@@ -101,14 +103,14 @@ public void create(int updateFlags, boolean local, IProgressMonitor monitor) thr
101103
assertCreateRequirements(store, localInfo, updateFlags);
102104
workspace.beginOperation(true);
103105
if (force && !Workspace.caseSensitive && localInfo.exists()) {
104-
String name = getLocalManager().getLocalName(store);
106+
String name = localInfo.getName();
105107
if (name == null || localInfo.getName().equals(name)) {
106108
delete(true, null);
107109
} else {
108110
// The file system is not case sensitive and a case variant exists at this
109111
// location
110112
String msg = NLS.bind(Messages.resources_existsLocalDifferentCase,
111-
IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString());
113+
Path.of(store.toString()).resolveSibling(name));
112114
throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null);
113115
}
114116
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -21,6 +21,7 @@
2121
package org.eclipse.core.internal.resources;
2222

2323
import java.net.URI;
24+
import java.nio.file.Path;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
2627
import java.util.Collection;
@@ -101,9 +102,10 @@ protected void assertCreateRequirements(IProjectDescription description) throws
101102
IFileStore store = getStore();
102103
IFileInfo localInfo = store.fetchInfo();
103104
if (localInfo.exists()) {
104-
String name = getLocalManager().getLocalName(store);
105+
String name = localInfo.getName();
105106
if (name != null && !store.getName().equals(name)) {
106-
String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString());
107+
String msg = NLS.bind(Messages.resources_existsLocalDifferentCase,
108+
Path.of(store.toString()).resolveSibling(name));
107109
throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null);
108110
}
109111
}

0 commit comments

Comments
 (0)