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
0
Merge Requests
0
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
iv
gitlab-workhorse
Commits
1629812b
Commit
1629812b
authored
Jan 20, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass content-length from gitlab-zip-cat
parent
1ccba44f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
cmd/gitlab-zip-cat/main.go
cmd/gitlab-zip-cat/main.go
+12
-3
internal/artifacts/artifact_download.go
internal/artifacts/artifact_download.go
+16
-2
No files found.
cmd/gitlab-zip-cat/main.go
View file @
1629812b
...
...
@@ -30,14 +30,14 @@ func main() {
archive
,
err
:=
zip
.
OpenReader
(
archiveFileName
)
if
err
!=
nil
{
printError
(
fmt
.
Errorf
(
"open %q: %v"
,
archiveFileName
,
err
))
os
.
Exit
(
notFound
)
exitNotFound
(
)
}
defer
archive
.
Close
()
file
:=
findFileInZip
(
fileName
,
&
archive
.
Reader
)
if
file
==
nil
{
printError
(
fmt
.
Errorf
(
"find %q in %q: not found"
,
fileName
,
archiveFileName
))
os
.
Exit
(
notFound
)
exitNotFound
(
)
}
// Start decompressing the file
reader
,
err
:=
file
.
Open
()
...
...
@@ -45,10 +45,14 @@ func main() {
fatalError
(
fmt
.
Errorf
(
"open %q in %q: %v"
,
fileName
,
archiveFileName
,
err
))
}
defer
reader
.
Close
()
if
_
,
err
:=
fmt
.
Printf
(
"%d
\n
"
,
file
.
UncompressedSize64
);
err
!=
nil
{
fatalError
(
fmt
.
Errorf
(
"write file size: %v"
,
err
))
}
if
_
,
err
:=
io
.
Copy
(
os
.
Stdout
,
reader
);
err
!=
nil
{
fatalError
(
fmt
.
Errorf
(
"write %q from %q to stdout: %v"
,
fileName
,
archiveFileName
,
err
))
}
}
func
findFileInZip
(
fileName
string
,
archive
*
zip
.
Reader
)
*
zip
.
File
{
...
...
@@ -68,3 +72,8 @@ func fatalError(err error) {
printError
(
err
)
os
.
Exit
(
1
)
}
func
exitNotFound
()
{
fmt
.
Printf
(
"%d
\n
"
,
-
notFound
)
// for the content-length reader
os
.
Exit
(
notFound
)
}
internal/artifacts/artifact_download.go
View file @
1629812b
...
...
@@ -3,6 +3,7 @@ package artifacts
import
(
"../api"
"../helper"
"bufio"
"encoding/base64"
"errors"
"fmt"
...
...
@@ -12,11 +13,14 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
)
const
exitStatusNotFound
=
2
var
notFoundString
=
fmt
.
Sprintf
(
"%d"
,
-
exitStatusNotFound
)
func
decodeFileEntry
(
entry
string
)
(
string
,
error
)
{
decoded
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
entry
)
if
err
!=
nil
{
...
...
@@ -45,14 +49,24 @@ func unpackFileFromZip(archiveFileName, fileName string, headers http.Header, ou
return
fmt
.
Errorf
(
"start %v: %v"
,
catFile
.
Args
,
err
)
}
defer
helper
.
CleanUpProcessGroup
(
catFile
)
basename
:=
filepath
.
Base
(
fileName
)
reader
:=
bufio
.
NewReader
(
stdout
)
contentLength
,
err
:=
reader
.
ReadString
(
'\n'
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"read content-length: %v"
,
err
)
}
contentLength
=
strings
.
TrimSuffix
(
contentLength
,
"
\n
"
)
if
contentLength
==
notFoundString
{
return
os
.
ErrNotExist
}
// Write http headers about the file
headers
.
Set
(
"Content-Length"
,
contentLength
)
headers
.
Set
(
"Content-Type"
,
detectFileContentType
(
fileName
))
headers
.
Set
(
"Content-Disposition"
,
"attachment; filename=
\"
"
+
escapeQuotes
(
basename
)
+
"
\"
"
)
// Copy file body to client
if
_
,
err
:=
io
.
Copy
(
output
,
stdout
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
output
,
reader
);
err
!=
nil
{
return
fmt
.
Errorf
(
"copy %v stdout: %v"
,
catFile
.
Args
,
err
)
}
...
...
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