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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
53e345d2
Commit
53e345d2
authored
Jan 26, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not make assumptions about non existing entries in artifacts
parent
57c3a8a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
23 deletions
+13
-23
internal/zipartifacts/metadata.go
internal/zipartifacts/metadata.go
+13
-23
No files found.
internal/zipartifacts/metadata.go
View file @
53e345d2
...
@@ -10,12 +10,11 @@ import (
...
@@ -10,12 +10,11 @@ import (
"path"
"path"
"sort"
"sort"
"strconv"
"strconv"
"time"
)
)
type
metadata
struct
{
type
metadata
struct
{
Modified
int64
`json:"modified"`
Modified
int64
`json:"modified
,omitempty
"`
Mode
string
`json:"mode"`
Mode
string
`json:"mode
,omitempty
"`
CRC
uint32
`json:"crc,omitempty"`
CRC
uint32
`json:"crc,omitempty"`
Size
uint64
`json:"size,omitempty"`
Size
uint64
`json:"size,omitempty"`
Zipped
uint64
`json:"zipped,omitempty"`
Zipped
uint64
`json:"zipped,omitempty"`
...
@@ -26,6 +25,10 @@ const MetadataHeaderPrefix = "\x00\x00\x00&" // length of string below, encoded
...
@@ -26,6 +25,10 @@ const MetadataHeaderPrefix = "\x00\x00\x00&" // length of string below, encoded
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
func
newMetadata
(
file
*
zip
.
File
)
metadata
{
func
newMetadata
(
file
*
zip
.
File
)
metadata
{
if
file
==
nil
{
return
metadata
{}
}
return
metadata
{
return
metadata
{
Modified
:
file
.
ModTime
()
.
Unix
(),
Modified
:
file
.
ModTime
()
.
Unix
(),
Mode
:
strconv
.
FormatUint
(
uint64
(
file
.
Mode
()
.
Perm
()),
8
),
Mode
:
strconv
.
FormatUint
(
uint64
(
file
.
Mode
()
.
Perm
()),
8
),
...
@@ -45,8 +48,8 @@ func (m metadata) writeEncoded(output io.Writer) error {
...
@@ -45,8 +48,8 @@ func (m metadata) writeEncoded(output io.Writer) error {
return
writeBytes
(
output
,
j
)
return
writeBytes
(
output
,
j
)
}
}
func
writeZipEntryMetadata
(
output
io
.
Writer
,
entry
*
zip
.
File
)
error
{
func
writeZipEntryMetadata
(
output
io
.
Writer
,
path
string
,
entry
*
zip
.
File
)
error
{
if
err
:=
writeString
(
output
,
entry
.
Name
);
err
!=
nil
{
if
err
:=
writeString
(
output
,
path
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -58,12 +61,11 @@ func writeZipEntryMetadata(output io.Writer, entry *zip.File) error {
...
@@ -58,12 +61,11 @@ 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
{
// Write metadata header
if
err
:=
writeString
(
output
,
MetadataHeader
);
err
!=
nil
{
if
err
:=
writeString
(
output
,
MetadataHeader
);
err
!=
nil
{
return
err
return
err
}
}
// Write empty error header
// Write empty error header
that we may need in the future
if
err
:=
writeString
(
output
,
"{}"
);
err
!=
nil
{
if
err
:=
writeString
(
output
,
"{}"
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -74,29 +76,17 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
...
@@ -74,29 +76,17 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
// Add missing entries
// Add missing entries
for
_
,
entry
:=
range
archive
.
File
{
for
_
,
entry
:=
range
archive
.
File
{
zipMap
[
entry
.
Name
]
=
entry
zipMap
[
entry
.
Name
]
=
entry
entryPath
:=
entry
.
Name
for
{
for
entryPath
:=
path
.
Dir
(
entry
.
Name
);
entryPath
!=
"."
&&
entryPath
!=
"/"
;
entryPath
=
path
.
Dir
(
entryPath
)
{
entryPath
=
path
.
Dir
(
entryPath
)
entryDir
:=
entryPath
+
"/"
entryDir
:=
entryPath
+
"/"
if
entryPath
==
"."
||
entryPath
==
"/"
{
break
}
if
_
,
ok
:=
zipMap
[
entryDir
];
!
ok
{
if
_
,
ok
:=
zipMap
[
entryDir
];
!
ok
{
var
missingHeader
zip
.
FileHeader
zipMap
[
entryDir
]
=
nil
missingHeader
.
Name
=
entryDir
missingHeader
.
SetModTime
(
time
.
Now
())
missingHeader
.
SetMode
(
os
.
FileMode
(
uint32
(
0755
)))
missingEntry
:=
&
zip
.
File
{
FileHeader
:
missingHeader
}
zipMap
[
entryDir
]
=
missingEntry
}
}
}
}
}
}
// Sort paths
// Sort paths
var
sortedPaths
[]
string
sortedPaths
:=
make
([]
string
,
0
,
len
(
zipMap
))
for
path
,
_
:=
range
zipMap
{
for
path
,
_
:=
range
zipMap
{
sortedPaths
=
append
(
sortedPaths
,
path
)
sortedPaths
=
append
(
sortedPaths
,
path
)
}
}
...
@@ -104,7 +94,7 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
...
@@ -104,7 +94,7 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
// Write all files
// Write all files
for
_
,
path
:=
range
sortedPaths
{
for
_
,
path
:=
range
sortedPaths
{
if
err
:=
writeZipEntryMetadata
(
output
,
zipMap
[
path
]);
err
!=
nil
{
if
err
:=
writeZipEntryMetadata
(
output
,
path
,
zipMap
[
path
]);
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