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 Sep 30, 2023
1 parent 7eb1b42 commit dd1fe91
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 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
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 dd1fe91

Please sign in to comment.