diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java index 14f6a86bfa5..6cf814d0a00 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -557,15 +557,6 @@ public IHistoryStore getHistoryStore() { return _historyStore; } - /** - * Returns the real name of the resource on disk. Returns null if no local - * file exists by that name. This is useful when dealing with - * case insensitive file systems. - */ - public String getLocalName(IFileStore target) { - return target.fetchInfo().getName(); - } - protected IPath getProjectDefaultLocation(IProject project) { return workspace.getRoot().getLocation().append(project.getFullPath()); } 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 6ca0f25e598..9312e8bd2b4 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -221,25 +222,24 @@ void checkCreatable() throws CoreException { IFileInfo create(int updateFlags, IProgressMonitor subMonitor, IFileStore store) throws CoreException, ResourceException { - String message; IFileInfo localInfo; if (BitMask.isSet(updateFlags, IResource.FORCE)) { - // Assume the file does not exist - otherwise implementation fails later + // Assume the file does not exist - otherwise implementation fails later // during actual write localInfo = new FileInfo(getName()); // with exists==false } else { - localInfo=store.fetchInfo(); + localInfo = store.fetchInfo(); if (localInfo.exists()) { // return an appropriate error message for case variant collisions if (!Workspace.caseSensitive) { - String name = getLocalManager().getLocalName(store); + String name = localInfo.getName(); if (name != null && !localInfo.getName().equals(name)) { - message = NLS.bind(Messages.resources_existsLocalDifferentCase, - IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString()); + String message = NLS.bind(Messages.resources_existsLocalDifferentCase, + Path.of(store.toString()).resolveSibling(name)); throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null); } } - message = NLS.bind(Messages.resources_fileExists, store.toString()); + String message = NLS.bind(Messages.resources_fileExists, store.toString()); throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), message, null); } } diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Folder.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Folder.java index 27c2ed1b28e..81178aca96e 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Folder.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Folder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ package org.eclipse.core.internal.resources; import java.net.URI; +import java.nio.file.Path; import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.internal.utils.Messages; @@ -47,9 +48,10 @@ protected void assertCreateRequirements(IFileStore store, IFileInfo localInfo, i if (!force && localInfo.exists()) { //return an appropriate error message for case variant collisions if (!Workspace.caseSensitive) { - String name = getLocalManager().getLocalName(store); + String name = localInfo.getName(); if (name != null && !store.getName().equals(name)) { - String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString()); + String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, + Path.of(store.toString()).resolveSibling(name)); throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null); } } @@ -101,14 +103,14 @@ public void create(int updateFlags, boolean local, IProgressMonitor monitor) thr assertCreateRequirements(store, localInfo, updateFlags); workspace.beginOperation(true); if (force && !Workspace.caseSensitive && localInfo.exists()) { - String name = getLocalManager().getLocalName(store); + String name = localInfo.getName(); if (name == null || localInfo.getName().equals(name)) { delete(true, null); } else { // The file system is not case sensitive and a case variant exists at this // location String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, - IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString()); + Path.of(store.toString()).resolveSibling(name)); throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null); } } diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java index 872223f6201..c7747fb5f85 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -21,6 +21,7 @@ package org.eclipse.core.internal.resources; import java.net.URI; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -101,9 +102,10 @@ protected void assertCreateRequirements(IProjectDescription description) throws IFileStore store = getStore(); IFileInfo localInfo = store.fetchInfo(); if (localInfo.exists()) { - String name = getLocalManager().getLocalName(store); + String name = localInfo.getName(); if (name != null && !store.getName().equals(name)) { - String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, IPath.fromOSString(store.toString()).removeLastSegments(1).append(name).toOSString()); + String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, + Path.of(store.toString()).resolveSibling(name)); throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null); } }