Skip to content

Commit

Permalink
HPCC4J-630 Ensure Filespray path constructed correctly
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
rpastrana committed Aug 20, 2024
1 parent 5551ce8 commit 237e156
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 237e156

Please sign in to comment.