From f05bc58f871edac00a71eae6434d7c25daa7ce09 Mon Sep 17 00:00:00 2001 From: Mads Hansen Date: Sun, 3 Jan 2021 18:53:35 -0500 Subject: [PATCH] Implement change to only lowerCase the Windows drive letter instead of the entire file path. Resolves #130 --- .../impl/PropertiesModuleManager.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/marklogic/client/ext/modulesloader/impl/PropertiesModuleManager.java b/src/main/java/com/marklogic/client/ext/modulesloader/impl/PropertiesModuleManager.java index 019bc9a..efa030c 100644 --- a/src/main/java/com/marklogic/client/ext/modulesloader/impl/PropertiesModuleManager.java +++ b/src/main/java/com/marklogic/client/ext/modulesloader/impl/PropertiesModuleManager.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; +import java.nio.file.Path; import java.util.Date; import java.util.Properties; @@ -129,14 +130,27 @@ public void saveLastLoadedTimestamp(File file, Date date) { * @param file * @return a string that can be used as a key for a Properties object */ - protected String buildKey(File file) { - String path = file.getAbsolutePath().toLowerCase(); - final String key = host != null ? host + ":" + path : path; - if (logger.isDebugEnabled()) { - logger.debug("Key for file " + file.getAbsolutePath() + ": " + key); - } - return key; - } + protected String buildKey(File file) { + String path = normalizeDriveLetter(file); + final String key = host != null ? host + ":" + path : path; + if (logger.isDebugEnabled()) { + logger.debug("Key for file " + file.getAbsolutePath() + ": " + key); + } + return key; + } + + protected String normalizeDriveLetter(File file) { + Path absolutePath = file.toPath().toAbsolutePath(); + String path = absolutePath.toString(); + Path root = absolutePath.getRoot(); + if (root != null) { + String drive = root.toString(); + if (path.startsWith(drive)) { + path = drive.toLowerCase() + path.substring(drive.length()); + } + } + return path; + } public void setMinimumFileTimestampToLoad(long minimumFileTimestampToLoad) { this.minimumFileTimestampToLoad = minimumFileTimestampToLoad;