From 237e1569a52e3758ec6aca5dd06a105de14d6370 Mon Sep 17 00:00:00 2001 From: Rodrigo Pastrana Date: Mon, 19 Aug 2024 16:52:10 -0400 Subject: [PATCH] HPCC4J-630 Ensure Filespray path constructed correctly - Add util method to append paths - Add junit test for new methods - Ensure wsfs methods use new method Signed-off-by: Rodrigo Pastrana --- .../ws/client/HPCCFileSprayClient.java | 2 +- .../hpccsystems/ws/client/utils/Utils.java | 31 +++++++++++++++++++ .../ws/client/utils/UtilsTest.java | 16 ++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java b/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java index a7283a6cd..187384942 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java @@ -1005,7 +1005,7 @@ public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZ SprayVariable request = new SprayVariable(); request.setSourceIP(targetDropZone.getNetAddress()); - request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName); + request.setSourcePath(Utils.ensureTrailingPathSlash(Utils.appendLinuxPathSections(targetDropZone.getPath(),sourceFileName))); request.setDestGroup(destGroup); request.setDestLogicalName(targetFileName); request.setOverwrite(overwrite); diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java index 16a4676d5..c000c106f 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java @@ -1114,6 +1114,37 @@ public static String ensureTrailingPathSlash(String path, char slash) return path; } + public static String appendLinuxPathSections(String prefixPath, String postfixPath) + { + return appendPathSections(prefixPath, LINUX_SEP, postfixPath); + } + + public static String appendWindowsPathSections(String prefixPath, String postfixPath) + { + return appendPathSections(prefixPath, WIN_SEP, postfixPath); + } + + public static String appendPathSections(String prefixPath, String postfixPath, String useLinuxSep) + { + return appendPathSections(prefixPath, useLinuxSep.equalsIgnoreCase("true") ? LINUX_SEP : WIN_SEP, postfixPath); + } + + public static String appendPathSections(String prefixPath, char slash, String postfixPath) + { + prefixPath = trimTrailing(prefixPath); + + if (prefixPath.length() == 0 || prefixPath.charAt(prefixPath.length()-1) != slash) + prefixPath = prefixPath + slash; + + postfixPath = postfixPath.trim(); + + if (postfixPath.length() > 0 && postfixPath.charAt(0) == slash) + prefixPath = prefixPath + postfixPath.substring(1); + else + prefixPath = prefixPath + postfixPath; + + return prefixPath; + } /** * Removes trailing whitespace characters from a string. * diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java b/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java index eef268e47..ef6912924 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java @@ -8,6 +8,22 @@ public class UtilsTest { + + @Test + public void testappendPathSections() + { + assertEquals(Character.toString(Utils.WIN_SEP), Utils.appendWindowsPathSections("", "")); + assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some\\ ", " \\path\\")); + assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some", " path\\")); + + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.appendLinuxPathSections("", "")); + assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path ", " relative/path")); + assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path/ ", " /relative/path")); + assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path")); + assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path")); + assertEquals("/relative/path", Utils.appendLinuxPathSections("/", " /relative/path")); + } + @Test public void testEnsureTrailingSlashTrailingWhiteSpace() {