Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
e1222e92
Commit
e1222e92
authored
Jan 21, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass zip entry name as Base64
parent
9713dc07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
19 deletions
+27
-19
cmd/gitlab-zip-cat/main.go
cmd/gitlab-zip-cat/main.go
+6
-1
internal/artifacts/artifact_download.go
internal/artifacts/artifact_download.go
+8
-18
internal/zipartifacts/entry.go
internal/zipartifacts/entry.go
+13
-0
No files found.
cmd/gitlab-zip-cat/main.go
View file @
e1222e92
...
@@ -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
))
...
...
internal/artifacts/artifact_download.go
View file @
e1222e92
...
@@ -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
...
...
internal/zipartifacts/entry.go
0 → 100644
View file @
e1222e92
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment