diff --git a/curl/upload/upload.go b/curl/upload/upload.go index bf3dcce3fcb51b847d6f97a643f185d0c9b69ed8..7931535f875a7bdc0dca717442d14ffa5c09258e 100644 --- a/curl/upload/upload.go +++ b/curl/upload/upload.go @@ -28,7 +28,7 @@ func (r *RunfileVar) Set(value string) error { return nil } -func upload(curl string, src string, dest string, retry uint64, retry_delay uint64) error { +func upload(curl string, src string, output string, dest string, retry uint64, retry_delay uint64) error { args := []string{ "--netrc", "--location", @@ -38,11 +38,24 @@ func upload(curl string, src string, dest string, retry uint64, retry_delay uint "--upload-file", src, "--url", dest, } + + if output != "" { + args = append(args, "--output", output) + } + cmd := exec.Command(curl, args...) + runfilesEnv, err := runfiles.Env() + if err != nil { + return err + } + + cmd.Env = append(os.Environ(), runfilesEnv...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr - err := cmd.Run() + err = cmd.Run() if err != nil { return err } @@ -79,6 +92,7 @@ func main() { var retry_delay uint64 var src RunfileVar var url string + var output string flag.Var(&curl, "curl", "The path to the curl bin") flag.Uint64Var(&retry, "retry", 0, "The number of times to retry the request") @@ -86,6 +100,7 @@ func main() { flag.Var(&src, "src", "Path to the source file") flag.StringVar(&url, "url", "", "The URL to upload to") + flag.StringVar(&output, "output", "", "Output file to use") args_file, err := runfiles.Rlocation("upload.args") if err != nil { @@ -98,8 +113,7 @@ func main() { } flag.Parse() - - err = upload(curl.String(), src.String(), url, retry, retry_delay) + err = upload(curl.String(), src.String(), output, url, retry, retry_delay) if err != nil { log.Fatal(err) } diff --git a/e2e/mock/curl.sh b/e2e/mock/curl.sh index 13572498ffe2e766d318c7b333e21d3cafa59d33..92734a17ca24a28f218aba044129f1172b7373aa 100755 --- a/e2e/mock/curl.sh +++ b/e2e/mock/curl.sh @@ -7,6 +7,7 @@ while test "${#}" -ne 0; do shift ;; "--upload-file") + # Check that the input files exist printf '%s\n' "${1}" shift if ! test -e "${1}"; then diff --git a/e2e/upload/file/BUILD.bazel b/e2e/upload/file/BUILD.bazel index d3e917f724142107663eee6ae7e0b43fd6476622..149088424d3c891673f0909127437d047a3fb2af 100644 --- a/e2e/upload/file/BUILD.bazel +++ b/e2e/upload/file/BUILD.bazel @@ -76,3 +76,21 @@ curl_upload_file( ) for test in ["basic", "original_filename", "injection", "no_extension"] ] + +# Check that --output is forwarded on to curl binary. +genrule( + name = "execute_with_output", + testonly = True, + outs = [ + "upload_with_output.out", + ], + cmd = "./$(location :upload_basic) --output output_file.txt > $@", + tools = [":upload_basic"], +) + +diff_file_test( + name = "test_output", + size = "small", + a = ":expected_with_output.txt", + b = ":upload_with_output.out" +) diff --git a/e2e/upload/file/expected_with_output.txt b/e2e/upload/file/expected_with_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7cf45654a5f1313f7b5aa4f7b63926f7ed929fc --- /dev/null +++ b/e2e/upload/file/expected_with_output.txt @@ -0,0 +1,13 @@ +--netrc +--location +--progress-bar +--retry +3 +--retry-delay +1 +--upload-file +input.txt +--url +https://test.case/directory/fixture.txt +--output +output_file.txt