Skip to content

Commit

Permalink
fix(client): improve reliability of file upload to pod (#6212)
Browse files Browse the repository at this point in the history
Fix: #6212

Signed-off-by: Florian Hussonnois <[email protected]>
  • Loading branch information
fhussonnois committed Aug 5, 2024
1 parent 74ba924 commit ec7fddb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static void addFileToTar(String fileName, File file, TarArchiveOutputStr

static String createExecCommandForUpload(String file) {
return String.format(
"mkdir -p %s && cat - > %s", shellQuote(getDirectoryFromFile(file)), shellQuote(file));
"mkdir -p %s && cat - > %s && echo $?", shellQuote(getDirectoryFromFile(file)), shellQuote(file));
}

private static String ensureEndsWithSlash(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ void withFileInRootPath_shouldCreateValidExecCommandForUpload() {
// When
String result = PodUpload.createExecCommandForUpload("/cp.log");
// Then
assertThat(result).isEqualTo("mkdir -p '/' && cat - > '/cp.log'");
assertThat(result).isEqualTo("mkdir -p '/' && cat - > '/cp.log' && echo $?");
}

@Test
void withNormalFile_shouldCreateValidExecCommandForUpload() {
// When
String result = PodUpload.createExecCommandForUpload("/tmp/foo/cp.log");
// Then
assertThat(result).isEqualTo("mkdir -p '/tmp/foo/' && cat - > '/tmp/foo/cp.log'");
assertThat(result).isEqualTo("mkdir -p '/tmp/foo/' && cat - > '/tmp/foo/cp.log' && echo $?");
}

//
Expand All @@ -66,15 +66,15 @@ void withSingleQuoteInPath() {
// When
String result = PodUpload.createExecCommandForUpload("/tmp/fo'o/cp.log");
// Then
assertThat(result).isEqualTo("mkdir -p '/tmp/fo\'\\'\'o/' && cat - > '/tmp/fo\'\\'\'o/cp.log'");
assertThat(result).isEqualTo("mkdir -p '/tmp/fo\'\\'\'o/' && cat - > '/tmp/fo\'\\'\'o/cp.log' && echo $?");
}

@Test
void withMultipleSingleQuotesInPath() {
// When
String result = PodUpload.createExecCommandForUpload("/tmp/f'o'o/c'p.log");
// Then
assertThat(result).isEqualTo("mkdir -p '/tmp/f\'\\'\'o\'\\'\'o/' && cat - > '/tmp/f\'\\'\'o\'\\'\'o/c\'\\'\'p.log'");
assertThat(result).isEqualTo("mkdir -p '/tmp/f\'\\'\'o\'\\'\'o/' && cat - > '/tmp/f\'\\'\'o\'\\'\'o/c\'\\'\'p.log' && echo $?");
}
}

Expand Down

0 comments on commit ec7fddb

Please sign in to comment.