diff --git a/curl/template/template.go b/curl/template/template.go index 8d4f7fcf199f4aa7af65b880e2de98fbe500c18b..1a0d740bc7d8de6272ea472d16561047f3de1bc4 100644 --- a/curl/template/template.go +++ b/curl/template/template.go @@ -47,7 +47,12 @@ type FileInfo struct { } func (f FileInfo) Basename() string { - return f.Stem.String() + "." + f.Extension.String() + extension := f.Extension.String() + stem := f.Stem.String() + if extension == "" { + return stem + } + return stem + "." + extension } func (f FileInfo) Path() string { diff --git a/curl/upload/file/rule.bzl b/curl/upload/file/rule.bzl index 58f9ff9b094fd29cf6df0b8f6fcb2d8a83657fc2..ddad0e119ba646ea185c54f979bc89fd0ca7da75 100644 --- a/curl/upload/file/rule.bzl +++ b/curl/upload/file/rule.bzl @@ -60,10 +60,10 @@ def implementation(ctx): csv = ctx.actions.declare_file("{}.upload.csv".format(ctx.label.name)) href = ctx.attr.url.rstrip("/").replace(",", "%2C") - dst = ctx.attr.dst args = ctx.actions.args() - args.add("{},{},{}".format(ctx.file.src.short_path, "{{{{.URL.Href}}}}/{}".format(dst), href)) + # SRC, DST, TEMPLATE, URL + args.add("{},{},{},{}".format(ctx.file.src.short_path, ctx.attr.dst, "{{.URL.Href}}/{{.File.Path}}", href)) ctx.actions.run( outputs = [csv], diff --git a/curl/upload/manifests/rule.bzl b/curl/upload/manifests/rule.bzl index 1d1bdef6b794d60e2ae25edbf146cefa3fb4dc38..713ebd9cb1cd3b09b393f663cfc5eb946186cdd5 100644 --- a/curl/upload/manifests/rule.bzl +++ b/curl/upload/manifests/rule.bzl @@ -71,8 +71,8 @@ def implementation(ctx): href = ctx.attr.url.rstrip("/").replace(",", "%2C") def _to_string(m): - # SRC,URL_TEMPL,URL - return "{},{},{}".format(m.file.short_path, m.url, href) + # SRC, DST, TEMPLATE, URL + return "{},{},{},{}".format(m.file.short_path, m.file.short_path, m.url, href) args = ctx.actions.args() args.add_all(manifests, map_each = _to_string, allow_closure = True) diff --git a/curl/upload/posix.tmpl.sh b/curl/upload/posix.tmpl.sh index 632ea482d61956bb9a11a7dd62987779da1caf85..05687f3e7f2eaf57cb53c9e44dfe50e1fac7f66d 100644 --- a/curl/upload/posix.tmpl.sh +++ b/curl/upload/posix.tmpl.sh @@ -51,13 +51,13 @@ upload() { "${2}" } -while IFS=, read -r SRC TMPL URL; do - DST=$( +while IFS=, read -r SRC DST TMPL URL; do + FULL_DST=$( "${TEMPLATE}" \ --url "${URL}" \ --template "${TMPL}" \ - --file "${SRC}" \ + --file "${DST}" \ ${@} ) - upload "${SRC}" "${DST}" + upload "${SRC}" "${FULL_DST}" done <"${CSV}" diff --git a/e2e/upload/file/BUILD.bazel b/e2e/upload/file/BUILD.bazel index 6826b0828727363027b0de7698639489904e2acc..0cdb0437a9cedcb31eb5e4771498bb6352845b60 100644 --- a/e2e/upload/file/BUILD.bazel +++ b/e2e/upload/file/BUILD.bazel @@ -25,3 +25,29 @@ diff_file_test( a = ":fixture.txt", b = ":execute", ) + + +curl_upload_file( + name = "upload_no_extension", + testonly = True, + src = ":fixture.txt", + dst = "directory/fixture", + url = "https://test.case", +) + +genrule( + name = "execute_no_extension", + testonly = True, + outs = [ + "upload_no_extension.out", + ], + cmd = "./$(location :upload_no_extension) > $@", + tools = [":upload_no_extension"], +) + +diff_file_test( + name = "test_no_extension", + size = "small", + a = ":fixture_no_extension.txt", + b = ":execute_no_extension", +) diff --git a/e2e/upload/file/fixture_no_extension.txt b/e2e/upload/file/fixture_no_extension.txt new file mode 100644 index 0000000000000000000000000000000000000000..806c14a07c5e5e2acd3136f902e6b61100c78b1b --- /dev/null +++ b/e2e/upload/file/fixture_no_extension.txt @@ -0,0 +1,10 @@ +--netrc +--location +--progress-bar +--retry +3 +--retry-delay +1 +--upload-file +fixture.txt +https://test.case/directory/fixture