Skip to content

Commit

Permalink
Paths starting with "//?/" on Windows are local
Browse files Browse the repository at this point in the history
The prefix might be used to support paths longer than MAX_PATH.
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson committed Oct 1, 2023
1 parent 7eb1b42 commit c358544
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ public void testConstructors() {
assertEquals("3.0.win", "D:/foo/abc.txt", IPath.forWindows("/D:/foo/abc.txt").toString());
// fullPath = new java.io.File("D:/").toURL().getPath()
assertEquals("3.1.win", "D:/", IPath.forWindows("/D:/").toString());

final String verylongpath = "C:/dev/verylongpath/00112233445566778899aabbccddeeff/00112233445566778899aabbccddeeff/00112233445566778899aabbccddeeff/"
+ "00112233445566778899aabbccddeeff/00112233445566778899aabbccddeeff/00112233445566778899aabbccddeeff/root/lib/gcc/arm-none-eabi/7.3.1/include-fixed";
anyPath = IPath.forWindows(verylongpath);
assertEquals("3.2.1.win", "C:", anyPath.getDevice());
assertEquals("3.3.2.win", "dev", anyPath.segment(0));
assertEquals("3.2.3.win", verylongpath, anyPath.toString());

anyPath = IPath.forWindows("//?/" + verylongpath);
assertEquals("3.3.1.win", "C:", anyPath.getDevice());
assertEquals("3.3.2.win", "dev", anyPath.segment(0));
assertEquals("3.3.3.win", verylongpath, anyPath.toString());
}

public void testFactoryMethods() {
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.common; singleton:=true
Bundle-Version: 3.18.100.qualifier
Bundle-Version: 3.18.200.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.core.internal.boot;x-friends:="org.eclipse.core.resources,org.eclipse.pde.build",
org.eclipse.core.internal.runtime;common=split;mandatory:=common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,15 @@ private static String backslashToForward(String path, boolean forWindows) {
//extract device
int i = fullPath.indexOf(DEVICE_SEPARATOR);
if (i != -1) {
//remove leading slash from device part to handle output of URL.getFile()
int start = fullPath.charAt(0) == SEPARATOR ? 1 : 0;
int start = 0;
if (fullPath.startsWith("//?/")) { //$NON-NLS-1$
// Paths prefixed with "//?/" are local paths. For details:
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces
start = 4;
} else if (fullPath.charAt(0) == SEPARATOR) {
// remove leading slash from device part to handle output of URL.getFile()
start = 1;
}
devicePart = fullPath.substring(start, i + 1);
fullPath = fullPath.substring(i + 1, fullPath.length());
}
Expand Down

0 comments on commit c358544

Please sign in to comment.