Skip to content

Commit de53c2a

Browse files
committed
[WIP] Fix UNC path on Windows
Fixes #1152 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 85de214 commit de53c2a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.eclipse.lemminx.uriresolver;
2+
3+
public class CacheResourceFileNotFoundException extends CacheResourceException {
4+
5+
public CacheResourceFileNotFoundException(String resourceURI, String message) {
6+
super(resourceURI, message);
7+
}
8+
9+
}

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/uriresolver/CacheResourcesManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.eclipse.lemminx.utils.ExceptionUtils.getRootCause;
1616

17+
import java.io.FileNotFoundException;
1718
import java.io.FileOutputStream;
1819
import java.io.IOException;
1920
import java.io.InputStream;
@@ -26,6 +27,7 @@
2627
import java.nio.file.Files;
2728
import java.nio.file.Path;
2829
import java.nio.file.Paths;
30+
import java.text.MessageFormat;
2931
import java.util.HashMap;
3032
import java.util.HashSet;
3133
import java.util.Map;
@@ -165,6 +167,16 @@ public Path getResource(final String resourceURI) throws IOException {
165167
CacheResourceDownloadingError.DOWNLOAD_DISABLED, null, null);
166168
}
167169

170+
URI resourceUriParsed = URI.create(resourceURI);
171+
if ("file".equals(resourceUriParsed.getScheme())) {
172+
// UNC path
173+
Path path = Path.of(resourceUriParsed);
174+
if (!Files.exists(path)) {
175+
throw new CacheResourceFileNotFoundException(path.toString(), "The network-accessible file '" + path.toString() + "' doesn't exist");
176+
}
177+
return path;
178+
}
179+
168180
if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) {
169181
throw new CacheResourceDownloadingException(resourceURI, resourceCachePath,
170182
CacheResourceDownloadingError.RESOURCE_NOT_IN_DEPLOYED_PATH, null, null);
@@ -309,6 +321,7 @@ public static Path getResourceCachePath(String resourceURI) throws IOException {
309321
}
310322

311323
public static Path getResourceCachePath(URI uri) throws IOException {
324+
312325
// Eliminate all path traversals
313326
URI normalizedUri = uri.normalize();
314327

0 commit comments

Comments
 (0)