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
57c3a8a8
Commit
57c3a8a8
authored
Jan 26, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort metadata entries before passing to IO buffer
parent
f1d320ed
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
19 deletions
+16
-19
internal/zipartifacts/metadata.go
internal/zipartifacts/metadata.go
+16
-19
No files found.
internal/zipartifacts/metadata.go
View file @
57c3a8a8
...
...
@@ -8,8 +8,8 @@ import (
"io"
"os"
"path"
"sort"
"strconv"
"strings"
"time"
)
...
...
@@ -22,8 +22,6 @@ type metadata struct {
Comment
string
`json:"comment,omitempty"`
}
type
zipDirMap
map
[
string
]
*
zip
.
File
const
MetadataHeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
...
...
@@ -70,44 +68,43 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
return
err
}
// Create map od directories in zip archive
dirMap
:=
make
(
zipDirMap
,
len
(
archive
.
File
))
for
_
,
entry
:=
range
archive
.
File
{
if
strings
.
HasSuffix
(
entry
.
Name
,
"/"
)
{
dirMap
[
entry
.
Name
]
=
entry
}
}
// Create map of files in zip archive
zipMap
:=
make
(
map
[
string
]
*
zip
.
File
,
len
(
archive
.
File
))
// Add missing entries
var
missingEntries
[]
*
zip
.
File
for
_
,
entry
:=
range
archive
.
File
{
zipMap
[
entry
.
Name
]
=
entry
entryPath
:=
entry
.
Name
for
{
entryPath
=
path
.
Dir
(
entryPath
)
entryDir
:=
entryPath
+
"/"
if
entryPath
==
"."
||
entryPath
==
"/"
{
break
}
if
_
,
ok
:=
dirMap
[
entryPath
];
!
ok
{
if
_
,
ok
:=
zipMap
[
entryDir
];
!
ok
{
var
missingHeader
zip
.
FileHeader
missingHeader
.
Name
=
entry
Path
missingHeader
.
Name
=
entry
Dir
missingHeader
.
SetModTime
(
time
.
Now
())
missingHeader
.
SetMode
(
os
.
FileMode
(
uint32
(
0755
)))
missingEntry
:=
&
zip
.
File
{
FileHeader
:
missingHeader
}
dirMap
[
entryPath
]
=
missingEntry
missingEntries
=
append
(
missingEntries
,
missingEntry
)
zipMap
[
entryDir
]
=
missingEntry
}
}
}
archive
.
File
=
append
(
archive
.
File
,
missingEntries
...
)
// Sort paths
var
sortedPaths
[]
string
for
path
,
_
:=
range
zipMap
{
sortedPaths
=
append
(
sortedPaths
,
path
)
}
sort
.
Strings
(
sortedPaths
)
// Write all files
for
_
,
entry
:=
range
archive
.
File
{
if
err
:=
writeZipEntryMetadata
(
output
,
entry
);
err
!=
nil
{
for
_
,
path
:=
range
sortedPaths
{
if
err
:=
writeZipEntryMetadata
(
output
,
zipMap
[
path
]
);
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