diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java index c1b39c494..891ed243e 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java @@ -20,6 +20,10 @@ public static String relativize(String rootPath, String longerThanRootPath) { if (File.separatorChar != '/') { longerThanRootPath = longerThanRootPath.replace('/', File.separatorChar); } + return relativizeInternal(fixDriveCase(rootPath), fixDriveCase(longerThanRootPath)); + } + + private static String relativizeInternal(String rootPath, String longerThanRootPath) { int index = longerThanRootPath.indexOf(rootPath); if (index < 0) { throw new IllegalArgumentException("The path '" + longerThanRootPath + "' does not contain the root path '" + rootPath + "'"); @@ -27,6 +31,15 @@ public static String relativize(String rootPath, String longerThanRootPath) { return longerThanRootPath.substring(index + rootPath.length() + 1); } + // sometimes the paths passed to relativize() have a lower case drive letter + public static String fixDriveCase(String path) { + if (path == null || path.length() < 2) return path; + if (Character.isLowerCase(path.charAt(0)) && path.charAt(1) == ':') { + return Character.toUpperCase(path.charAt(0)) + ':' + path.substring(2); + } + return path; + } + public static String getParent(String path) { int i = path.lastIndexOf(File.separatorChar); if (i <= 0) return StringUtils.EMPTY;