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
Kazuhiko Shiozaki
gitlab-workhorse
Commits
bc69d851
Commit
bc69d851
authored
Jan 21, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up sharing of status codes
parent
af40facc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
19 deletions
+24
-19
cmd/gitlab-zip-cat/main.go
cmd/gitlab-zip-cat/main.go
+3
-3
cmd/gitlab-zip-metadata/main.go
cmd/gitlab-zip-metadata/main.go
+3
-3
internal/artifacts/artifact_download.go
internal/artifacts/artifact_download.go
+3
-4
internal/artifacts/artifacts_upload.go
internal/artifacts/artifacts_upload.go
+2
-2
internal/artifacts/artifacts_upload_test.go
internal/artifacts/artifacts_upload_test.go
+2
-2
internal/zipartifacts/codes.go
internal/zipartifacts/codes.go
+7
-0
internal/zipartifacts/metadata.go
internal/zipartifacts/metadata.go
+4
-5
No files found.
cmd/gitlab-zip-cat/main.go
View file @
bc69d851
package
main
package
main
import
(
import
(
"../../internal/zipartifacts"
"archive/zip"
"archive/zip"
"flag"
"flag"
"fmt"
"fmt"
...
@@ -9,7 +10,6 @@ import (
...
@@ -9,7 +10,6 @@ import (
"os"
"os"
)
)
const
notFound
=
2
const
progName
=
"gitlab-zip-cat"
const
progName
=
"gitlab-zip-cat"
var
Version
=
"unknown"
var
Version
=
"unknown"
...
@@ -79,6 +79,6 @@ func fatalError(err error) {
...
@@ -79,6 +79,6 @@ func fatalError(err error) {
}
}
func
exitNotFound
()
{
func
exitNotFound
()
{
fmt
.
Printf
(
"%d
\n
"
,
-
n
otFound
)
// for the content-length reader
fmt
.
Printf
(
"%d
\n
"
,
-
zipartifacts
.
StatusEntryN
otFound
)
// for the content-length reader
os
.
Exit
(
n
otFound
)
os
.
Exit
(
zipartifacts
.
StatusEntryN
otFound
)
}
}
cmd/gitlab-zip-metadata/main.go
View file @
bc69d851
package
main
package
main
import
(
import
(
"../../internal/zip
metadata
"
"../../internal/zip
artifacts
"
"flag"
"flag"
"fmt"
"fmt"
"os"
"os"
...
@@ -26,10 +26,10 @@ func main() {
...
@@ -26,10 +26,10 @@ func main() {
fmt
.
Fprintf
(
os
.
Stderr
,
"Usage: %s FILE.ZIP"
,
progName
)
fmt
.
Fprintf
(
os
.
Stderr
,
"Usage: %s FILE.ZIP"
,
progName
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
if
err
:=
zip
metadata
.
GenerateZipMetadataFromFile
(
os
.
Args
[
1
],
os
.
Stdout
);
err
!=
nil
{
if
err
:=
zip
artifacts
.
GenerateZipMetadataFromFile
(
os
.
Args
[
1
],
os
.
Stdout
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%s: %v
\n
"
,
progName
,
err
)
fmt
.
Fprintf
(
os
.
Stderr
,
"%s: %v
\n
"
,
progName
,
err
)
if
err
==
os
.
ErrInvalid
{
if
err
==
os
.
ErrInvalid
{
os
.
Exit
(
zip
metadata
.
StatusNotZip
)
os
.
Exit
(
zip
artifacts
.
StatusNotZip
)
}
}
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
...
internal/artifacts/artifact_download.go
View file @
bc69d851
...
@@ -3,6 +3,7 @@ package artifacts
...
@@ -3,6 +3,7 @@ package artifacts
import
(
import
(
"../api"
"../api"
"../helper"
"../helper"
"../zipartifacts"
"bufio"
"bufio"
"encoding/base64"
"encoding/base64"
"errors"
"errors"
...
@@ -17,9 +18,7 @@ import (
...
@@ -17,9 +18,7 @@ import (
"syscall"
"syscall"
)
)
const
exitStatusNotFound
=
2
var
notFoundString
=
fmt
.
Sprintf
(
"%d"
,
-
zipartifacts
.
StatusEntryNotFound
)
var
notFoundString
=
fmt
.
Sprintf
(
"%d"
,
-
exitStatusNotFound
)
func
decodeFileEntry
(
entry
string
)
(
string
,
error
)
{
func
decodeFileEntry
(
entry
string
)
(
string
,
error
)
{
decoded
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
entry
)
decoded
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
entry
)
...
@@ -72,7 +71,7 @@ func unpackFileFromZip(archiveFileName, fileName string, headers http.Header, ou
...
@@ -72,7 +71,7 @@ func unpackFileFromZip(archiveFileName, fileName string, headers http.Header, ou
}
}
if
err
:=
catFile
.
Wait
();
err
!=
nil
{
if
err
:=
catFile
.
Wait
();
err
!=
nil
{
if
st
,
ok
:=
helper
.
ExitStatus
(
err
);
ok
&&
st
==
exitStatus
NotFound
{
if
st
,
ok
:=
helper
.
ExitStatus
(
err
);
ok
&&
st
==
zipartifacts
.
StatusEntry
NotFound
{
return
os
.
ErrNotExist
return
os
.
ErrNotExist
}
}
...
...
internal/artifacts/artifacts_upload.go
View file @
bc69d851
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
"../api"
"../api"
"../helper"
"../helper"
"../upload"
"../upload"
"../zip
metadata
"
"../zip
artifacts
"
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
...
@@ -49,7 +49,7 @@ func (a *artifactsUploadProcessor) ProcessFile(formName, fileName string, writer
...
@@ -49,7 +49,7 @@ func (a *artifactsUploadProcessor) ProcessFile(formName, fileName string, writer
}
}
defer
helper
.
CleanUpProcessGroup
(
zipMd
)
defer
helper
.
CleanUpProcessGroup
(
zipMd
)
if
err
:=
zipMd
.
Wait
();
err
!=
nil
{
if
err
:=
zipMd
.
Wait
();
err
!=
nil
{
if
st
,
ok
:=
helper
.
ExitStatus
(
err
);
ok
&&
st
==
zip
metadata
.
StatusNotZip
{
if
st
,
ok
:=
helper
.
ExitStatus
(
err
);
ok
&&
st
==
zip
artifacts
.
StatusNotZip
{
return
nil
return
nil
}
}
return
err
return
err
...
...
internal/artifacts/artifacts_upload_test.go
View file @
bc69d851
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"../helper"
"../helper"
"../proxy"
"../proxy"
"../testhelper"
"../testhelper"
"../zip
metadata
"
"../zip
artifacts
"
"archive/zip"
"archive/zip"
"bytes"
"bytes"
"compress/gzip"
"compress/gzip"
...
@@ -72,7 +72,7 @@ func testArtifactsUploadServer(t *testing.T, tempPath string) *httptest.Server {
...
@@ -72,7 +72,7 @@ func testArtifactsUploadServer(t *testing.T, tempPath string) *httptest.Server {
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
return
return
}
}
if
!
bytes
.
HasPrefix
(
metadata
,
[]
byte
(
zip
metadata
.
HeaderPrefix
+
zipmetadata
.
Header
))
{
if
!
bytes
.
HasPrefix
(
metadata
,
[]
byte
(
zip
artifacts
.
MetadataHeaderPrefix
+
zipartifacts
.
Metadata
Header
))
{
w
.
WriteHeader
(
400
)
w
.
WriteHeader
(
400
)
return
return
}
}
...
...
internal/zipartifacts/codes.go
0 → 100644
View file @
bc69d851
package
zipartifacts
// These are exit codes used by subprocesses in cmd/gitlab-zip-xxx
const
(
StatusNotZip
=
10
+
iota
StatusEntryNotFound
)
internal/zip
metadata
/metadata.go
→
internal/zip
artifacts
/metadata.go
View file @
bc69d851
package
zip
metadata
package
zip
artifacts
import
(
import
(
"archive/zip"
"archive/zip"
...
@@ -19,9 +19,8 @@ type metadata struct {
...
@@ -19,9 +19,8 @@ type metadata struct {
Comment
string
`json:"comment,omitempty"`
Comment
string
`json:"comment,omitempty"`
}
}
const
HeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
MetadataHeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
Header
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
const
StatusNotZip
=
2
func
newMetadata
(
file
*
zip
.
File
)
metadata
{
func
newMetadata
(
file
*
zip
.
File
)
metadata
{
return
metadata
{
return
metadata
{
...
@@ -57,7 +56,7 @@ func writeZipEntryMetadata(output io.Writer, entry *zip.File) error {
...
@@ -57,7 +56,7 @@ func writeZipEntryMetadata(output io.Writer, entry *zip.File) error {
}
}
func
generateZipMetadata
(
output
io
.
Writer
,
archive
*
zip
.
Reader
)
error
{
func
generateZipMetadata
(
output
io
.
Writer
,
archive
*
zip
.
Reader
)
error
{
err
:=
writeString
(
output
,
Header
)
err
:=
writeString
(
output
,
Metadata
Header
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
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