1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 393791 - Cannot substitute Windows path to Unix path on Linux

This commit is contained in:
Scott Tepavich 2012-11-07 13:02:26 -08:00 committed by Pawel Piech
parent b004558b81
commit da9df79e53
2 changed files with 26 additions and 28 deletions

View file

@ -74,34 +74,32 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
public static IPath createPath(String path) { public static IPath createPath(String path) {
if (path == null) if (path == null)
return null; return null;
if (path.contains("\\")) { //$NON-NLS-1$
// handle Windows slashes and canonicalize // Check for windows full-path formatting.
path = path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ if (path.matches("^([a-zA-Z])[:](.*)$")) { //$NON-NLS-1$
String device = null;
String missingfile = path.replace("\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
int idx = missingfile.indexOf(":"); //$NON-NLS-1$
if ( idx > 0 ) {
device = missingfile.substring(0, idx + 1);
missingfile = missingfile.substring(idx + 1);
}
return new Path(device, missingfile);
} }
// also check for device or UNC int idx = 0;
int firstSep = path.indexOf("/"); //$NON-NLS-1$ // Cygwin or UNC path
int idx = path.indexOf(":"); //$NON-NLS-1$ if (path.startsWith("//")) { //$NON-NLS-1$
// ':' indicates a Windows device separator if it comes before String network;
// the first segment separator idx = path.indexOf("/", 2); //$NON-NLS-1$
if (idx > 0 && (firstSep < 0 || idx < firstSep)) { if (idx > 0) {
String device = path.substring(0, idx + 1); network = path.substring(0, idx);
path = path.substring(idx + 1); path = path.substring(idx);
return new Path(path).setDevice(device); } else {
} else { network = path;
// Cygwin or UNC path path = ""; //$NON-NLS-1$
if (path.startsWith("//")) { //$NON-NLS-1$
String network;
idx = path.indexOf("/", 2); //$NON-NLS-1$
if (idx > 0) {
network = path.substring(0, idx);
path = path.substring(idx);
} else {
network = path;
path = ""; //$NON-NLS-1$
}
return new Path(network, path).makeUNC(true);
} }
return new Path(network, path).makeUNC(true);
} }
// fallthrough // fallthrough

View file

@ -37,7 +37,7 @@ public class MapEntrySourceContainerType extends AbstractSourceContainerTypeDele
Element element = (Element)node; Element element = (Element)node;
if (ELEMENT_NAME.equals(element.getNodeName())) { if (ELEMENT_NAME.equals(element.getNodeName())) {
String path = element.getAttribute(BACKEND_PATH); String path = element.getAttribute(BACKEND_PATH);
IPath backend = new Path(path); IPath backend = MapEntrySourceContainer.createPath(path);
if (!backend.isValidPath(path)) { if (!backend.isValidPath(path)) {
abort(InternalSourceLookupMessages.MapEntrySourceContainerType_0, null); abort(InternalSourceLookupMessages.MapEntrySourceContainerType_0, null);
} }