Commit 8d6721c6 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Support more archive extensions in SendArchive

Closes https://gitlab.com/gitlab-org/gitlab-workhorse/issues/60
parent 2f25e568
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
Formerly known as 'gitlab-git-http-server'. Formerly known as 'gitlab-git-http-server'.
v0.8.2 (not released yet)
Recognize more archive formats in git.SendArchive.
v0.8.1 v0.8.1
Add Sentry (raven-go) for remote error tracking. Add Sentry (raven-go) for remote error tracking.
......
...@@ -40,16 +40,8 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string ...@@ -40,16 +40,8 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
var format string var format string
urlPath := r.URL.Path urlPath := r.URL.Path
switch filepath.Base(urlPath) { format, ok := parseBasename(filepath.Base(urlPath))
case "archive.zip": if !ok {
format = "zip"
case "archive.tar":
format = "tar"
case "archive", "archive.tar.gz":
format = "tar.gz"
case "archive.tar.bz2":
format = "tar.bz2"
default:
helper.Fail500(w, fmt.Errorf("handleGetArchive: invalid format: %s", urlPath)) helper.Fail500(w, fmt.Errorf("handleGetArchive: invalid format: %s", urlPath))
return return
} }
...@@ -183,3 +175,22 @@ func finalizeCachedArchive(tempFile *os.File, archivePath string) error { ...@@ -183,3 +175,22 @@ func finalizeCachedArchive(tempFile *os.File, archivePath string) error {
} }
return os.Link(tempFile.Name(), archivePath) return os.Link(tempFile.Name(), archivePath)
} }
func parseBasename(basename string) (string, bool) {
var format string
switch basename {
case "archive.zip":
format = "zip"
case "archive.tar":
format = "tar"
case "archive", "archive.tar.gz", "archive.tgz", "archive.gz":
format = "tar.gz"
case "archive.tar.bz2", "archive.tbz", "archive.tbz2", "archive.tb2", "archive.bz2":
format = "tar.bz2"
default:
return "", false
}
return format, true
}
package git
import (
"testing"
)
func TestParseBasename(t *testing.T) {
for _, testCase := range []struct{ in, out string }{
{"", "tar.gz"},
{".tar.gz", "tar.gz"},
{".tgz", "tar.gz"},
{".gz", "tar.gz"},
{".tar.bz2", "tar.bz2"},
{".tbz", "tar.bz2"},
{".tbz2", "tar.bz2"},
{".tb2", "tar.bz2"},
{".bz2", "tar.bz2"},
} {
basename := "archive" + testCase.in
out, ok := parseBasename(basename)
if !ok {
t.Fatalf("parseBasename did not recognize %q", basename)
}
if out != testCase.out {
t.Fatalf("expected %q, got %q", testCase.out, out)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment