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
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
Hide 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 (
...
@@ -8,8 +8,8 @@ import (
"io"
"io"
"os"
"os"
"path"
"path"
"sort"
"strconv"
"strconv"
"strings"
"time"
"time"
)
)
...
@@ -22,8 +22,6 @@ type metadata struct {
...
@@ -22,8 +22,6 @@ type metadata struct {
Comment
string
`json:"comment,omitempty"`
Comment
string
`json:"comment,omitempty"`
}
}
type
zipDirMap
map
[
string
]
*
zip
.
File
const
MetadataHeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
MetadataHeaderPrefix
=
"
\x00\x00\x00
&"
// length of string below, encoded properly
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
...
@@ -70,44 +68,43 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
...
@@ -70,44 +68,43 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
return
err
return
err
}
}
// Create map od directories in zip archive
// Create map of files in zip archive
dirMap
:=
make
(
zipDirMap
,
len
(
archive
.
File
))
zipMap
:=
make
(
map
[
string
]
*
zip
.
File
,
len
(
archive
.
File
))
for
_
,
entry
:=
range
archive
.
File
{
if
strings
.
HasSuffix
(
entry
.
Name
,
"/"
)
{
dirMap
[
entry
.
Name
]
=
entry
}
}
// Add missing entries
// Add missing entries
var
missingEntries
[]
*
zip
.
File
for
_
,
entry
:=
range
archive
.
File
{
for
_
,
entry
:=
range
archive
.
File
{
zipMap
[
entry
.
Name
]
=
entry
entryPath
:=
entry
.
Name
entryPath
:=
entry
.
Name
for
{
for
{
entryPath
=
path
.
Dir
(
entryPath
)
entryPath
=
path
.
Dir
(
entryPath
)
entryDir
:=
entryPath
+
"/"
if
entryPath
==
"."
||
entryPath
==
"/"
{
if
entryPath
==
"."
||
entryPath
==
"/"
{
break
break
}
}
if
_
,
ok
:=
dirMap
[
entryPath
];
!
ok
{
if
_
,
ok
:=
zipMap
[
entryDir
];
!
ok
{
var
missingHeader
zip
.
FileHeader
var
missingHeader
zip
.
FileHeader
missingHeader
.
Name
=
entry
Path
missingHeader
.
Name
=
entry
Dir
missingHeader
.
SetModTime
(
time
.
Now
())
missingHeader
.
SetModTime
(
time
.
Now
())
missingHeader
.
SetMode
(
os
.
FileMode
(
uint32
(
0755
)))
missingHeader
.
SetMode
(
os
.
FileMode
(
uint32
(
0755
)))
missingEntry
:=
&
zip
.
File
{
FileHeader
:
missingHeader
}
missingEntry
:=
&
zip
.
File
{
FileHeader
:
missingHeader
}
dirMap
[
entryPath
]
=
missingEntry
zipMap
[
entryDir
]
=
missingEntry
missingEntries
=
append
(
missingEntries
,
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
// Write all files
for
_
,
entry
:=
range
archive
.
File
{
for
_
,
path
:=
range
sortedPaths
{
if
err
:=
writeZipEntryMetadata
(
output
,
entry
);
err
!=
nil
{
if
err
:=
writeZipEntryMetadata
(
output
,
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