Commit e1222e92 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Pass zip entry name as Base64

parent 9713dc07
...@@ -31,7 +31,12 @@ func main() { ...@@ -31,7 +31,12 @@ func main() {
} }
archiveFileName := os.Args[1] archiveFileName := os.Args[1]
fileName := os.Args[2]
fileName, err := zipartifacts.DecodeFileEntry(os.Args[2])
if err != nil {
fatalError(fmt.Errorf("decode entry %q: %v", os.Args[2], err))
}
archive, err := zip.OpenReader(archiveFileName) archive, err := zip.OpenReader(archiveFileName)
if err != nil { if err != nil {
printError(fmt.Errorf("open %q: %v", archiveFileName, err)) printError(fmt.Errorf("open %q: %v", archiveFileName, err))
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"../helper" "../helper"
"../zipartifacts" "../zipartifacts"
"bufio" "bufio"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io" "io"
...@@ -20,14 +19,6 @@ import ( ...@@ -20,14 +19,6 @@ import (
var notFoundString = fmt.Sprintf("%d", -zipartifacts.StatusEntryNotFound) var notFoundString = fmt.Sprintf("%d", -zipartifacts.StatusEntryNotFound)
func decodeFileEntry(entry string) (string, error) {
decoded, err := base64.StdEncoding.DecodeString(entry)
if err != nil {
return "", err
}
return string(decoded), nil
}
func detectFileContentType(fileName string) string { func detectFileContentType(fileName string) string {
contentType := mime.TypeByExtension(filepath.Ext(fileName)) contentType := mime.TypeByExtension(filepath.Ext(fileName))
if contentType == "" { if contentType == "" {
...@@ -36,8 +27,13 @@ func detectFileContentType(fileName string) string { ...@@ -36,8 +27,13 @@ func detectFileContentType(fileName string) string {
return contentType return contentType
} }
func unpackFileFromZip(archiveFileName, fileName string, headers http.Header, output io.Writer) error { func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Header, output io.Writer) error {
catFile := exec.Command("gitlab-zip-cat", archiveFileName, fileName) fileName, err := zipartifacts.DecodeFileEntry(encodedFilename)
if err != nil {
return err
}
catFile := exec.Command("gitlab-zip-cat", archiveFileName, encodedFilename)
catFile.Stderr = os.Stderr catFile.Stderr = os.Stderr
catFile.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} catFile.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
stdout, err := catFile.StdoutPipe() stdout, err := catFile.StdoutPipe()
...@@ -89,13 +85,7 @@ func DownloadArtifact(myAPI *api.API) http.Handler { ...@@ -89,13 +85,7 @@ func DownloadArtifact(myAPI *api.API) http.Handler {
return return
} }
fileName, err := decodeFileEntry(a.Entry) err := unpackFileFromZip(a.Archive, a.Entry, w.Header(), w)
if err != nil {
helper.Fail500(w, err)
return
}
err = unpackFileFromZip(a.Archive, fileName, w.Header(), w)
if os.IsNotExist(err) { if os.IsNotExist(err) {
http.NotFound(w, r) http.NotFound(w, r)
return return
......
package zipartifacts
import (
"encoding/base64"
)
func DecodeFileEntry(entry string) (string, error) {
decoded, err := base64.StdEncoding.DecodeString(entry)
if err != nil {
return "", err
}
return string(decoded), nil
}
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