Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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-ce
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
import
(
"../../internal/zipartifacts"
"archive/zip"
"flag"
"fmt"
...
...
@@ -9,7 +10,6 @@ import (
"os"
)
const
notFound
=
2
const
progName
=
"gitlab-zip-cat"
var
Version
=
"unknown"
...
...
@@ -79,6 +79,6 @@ func fatalError(err error) {
}
func
exitNotFound
()
{
fmt
.
Printf
(
"%d
\n
"
,
-
n
otFound
)
// for the content-length reader
os
.
Exit
(
n
otFound
)
fmt
.
Printf
(
"%d
\n
"
,
-
zipartifacts
.
StatusEntryN
otFound
)
// for the content-length reader
os
.
Exit
(
zipartifacts
.
StatusEntryN
otFound
)
}
cmd/gitlab-zip-metadata/main.go
View file @
bc69d851
package
main
import
(
"../../internal/zip
metadata
"
"../../internal/zip
artifacts
"
"flag"
"fmt"
"os"
...
...
@@ -26,10 +26,10 @@ func main() {
fmt
.
Fprintf
(
os
.
Stderr
,
"Usage: %s FILE.ZIP"
,
progName
)
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
)
if
err
==
os
.
ErrInvalid
{
os
.
Exit
(
zip
metadata
.
StatusNotZip
)
os
.
Exit
(
zip
artifacts
.
StatusNotZip
)
}
os
.
Exit
(
1
)
}
...
...
internal/artifacts/artifact_download.go
View file @
bc69d851
...
...
@@ -3,6 +3,7 @@ package artifacts
import
(
"../api"
"../helper"
"../zipartifacts"
"bufio"
"encoding/base64"
"errors"
...
...
@@ -17,9 +18,7 @@ import (
"syscall"
)
const
exitStatusNotFound
=
2
var
notFoundString
=
fmt
.
Sprintf
(
"%d"
,
-
exitStatusNotFound
)
var
notFoundString
=
fmt
.
Sprintf
(
"%d"
,
-
zipartifacts
.
StatusEntryNotFound
)
func
decodeFileEntry
(
entry
string
)
(
string
,
error
)
{
decoded
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
entry
)
...
...
@@ -72,7 +71,7 @@ func unpackFileFromZip(archiveFileName, fileName string, headers http.Header, ou
}
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
}
...
...
internal/artifacts/artifacts_upload.go
View file @
bc69d851
...
...
@@ -4,7 +4,7 @@ import (
"../api"
"../helper"
"../upload"
"../zip
metadata
"
"../zip
artifacts
"
"errors"
"fmt"
"io/ioutil"
...
...
@@ -49,7 +49,7 @@ func (a *artifactsUploadProcessor) ProcessFile(formName, fileName string, writer
}
defer
helper
.
CleanUpProcessGroup
(
zipMd
)
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
err
...
...
internal/artifacts/artifacts_upload_test.go
View file @
bc69d851
...
...
@@ -5,7 +5,7 @@ import (
"../helper"
"../proxy"
"../testhelper"
"../zip
metadata
"
"../zip
artifacts
"
"archive/zip"
"bytes"
"compress/gzip"
...
...
@@ -72,7 +72,7 @@ func testArtifactsUploadServer(t *testing.T, tempPath string) *httptest.Server {
w
.
WriteHeader
(
404
)
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
)
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
(
"archive/zip"
...
...
@@ -19,9 +19,8 @@ type metadata struct {
Comment
string
`json:"comment,omitempty"`
}
const
HeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
Header
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
const
StatusNotZip
=
2
const
MetadataHeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
func
newMetadata
(
file
*
zip
.
File
)
metadata
{
return
metadata
{
...
...
@@ -57,7 +56,7 @@ func writeZipEntryMetadata(output io.Writer, entry *zip.File) error {
}
func
generateZipMetadata
(
output
io
.
Writer
,
archive
*
zip
.
Reader
)
error
{
err
:=
writeString
(
output
,
Header
)
err
:=
writeString
(
output
,
Metadata
Header
)
if
err
!=
nil
{
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