Skip to content

Commit 237e156

Browse files
committed
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 <[email protected]>
1 parent 5551ce8 commit 237e156

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZ
10051005

10061006
SprayVariable request = new SprayVariable();
10071007
request.setSourceIP(targetDropZone.getNetAddress());
1008-
request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName);
1008+
request.setSourcePath(Utils.ensureTrailingPathSlash(Utils.appendLinuxPathSections(targetDropZone.getPath(),sourceFileName)));
10091009
request.setDestGroup(destGroup);
10101010
request.setDestLogicalName(targetFileName);
10111011
request.setOverwrite(overwrite);

wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java

+31
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,37 @@ public static String ensureTrailingPathSlash(String path, char slash)
11141114
return path;
11151115
}
11161116

1117+
public static String appendLinuxPathSections(String prefixPath, String postfixPath)
1118+
{
1119+
return appendPathSections(prefixPath, LINUX_SEP, postfixPath);
1120+
}
1121+
1122+
public static String appendWindowsPathSections(String prefixPath, String postfixPath)
1123+
{
1124+
return appendPathSections(prefixPath, WIN_SEP, postfixPath);
1125+
}
1126+
1127+
public static String appendPathSections(String prefixPath, String postfixPath, String useLinuxSep)
1128+
{
1129+
return appendPathSections(prefixPath, useLinuxSep.equalsIgnoreCase("true") ? LINUX_SEP : WIN_SEP, postfixPath);
1130+
}
1131+
1132+
public static String appendPathSections(String prefixPath, char slash, String postfixPath)
1133+
{
1134+
prefixPath = trimTrailing(prefixPath);
1135+
1136+
if (prefixPath.length() == 0 || prefixPath.charAt(prefixPath.length()-1) != slash)
1137+
prefixPath = prefixPath + slash;
1138+
1139+
postfixPath = postfixPath.trim();
1140+
1141+
if (postfixPath.length() > 0 && postfixPath.charAt(0) == slash)
1142+
prefixPath = prefixPath + postfixPath.substring(1);
1143+
else
1144+
prefixPath = prefixPath + postfixPath;
1145+
1146+
return prefixPath;
1147+
}
11171148
/**
11181149
* Removes trailing whitespace characters from a string.
11191150
*

wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
public class UtilsTest
1010
{
11+
12+
@Test
13+
public void testappendPathSections()
14+
{
15+
assertEquals(Character.toString(Utils.WIN_SEP), Utils.appendWindowsPathSections("", ""));
16+
assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some\\ ", " \\path\\"));
17+
assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some", " path\\"));
18+
19+
assertEquals(Character.toString(Utils.LINUX_SEP), Utils.appendLinuxPathSections("", ""));
20+
assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path ", " relative/path"));
21+
assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path/ ", " /relative/path"));
22+
assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path"));
23+
assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path"));
24+
assertEquals("/relative/path", Utils.appendLinuxPathSections("/", " /relative/path"));
25+
}
26+
1127
@Test
1228
public void testEnsureTrailingSlashTrailingWhiteSpace()
1329
{

0 commit comments

Comments
 (0)