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
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
Show 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 (
"path"
"sort"
"strconv"
"time"
)
type
metadata
struct
{
Modified
int64
`json:"modified"`
Mode
string
`json:"mode"`
Modified
int64
`json:"modified
,omitempty
"`
Mode
string
`json:"mode
,omitempty
"`
CRC
uint32
`json:"crc,omitempty"`
Size
uint64
`json:"size,omitempty"`
Zipped
uint64
`json:"zipped,omitempty"`
...
...
@@ -26,6 +25,10 @@ const MetadataHeaderPrefix = "\x00\x00\x00&" // length of string below, encoded
const
MetadataHeader
=
"GitLab Build Artifacts Metadata 0.0.2
\n
"
func
newMetadata
(
file
*
zip
.
File
)
metadata
{
if
file
==
nil
{
return
metadata
{}
}
return
metadata
{
Modified
:
file
.
ModTime
()
.
Unix
(),
Mode
:
strconv
.
FormatUint
(
uint64
(
file
.
Mode
()
.
Perm
()),
8
),
...
...
@@ -45,8 +48,8 @@ func (m metadata) writeEncoded(output io.Writer) error {
return
writeBytes
(
output
,
j
)
}
func
writeZipEntryMetadata
(
output
io
.
Writer
,
entry
*
zip
.
File
)
error
{
if
err
:=
writeString
(
output
,
entry
.
Name
);
err
!=
nil
{
func
writeZipEntryMetadata
(
output
io
.
Writer
,
path
string
,
entry
*
zip
.
File
)
error
{
if
err
:=
writeString
(
output
,
path
);
err
!=
nil
{
return
err
}
...
...
@@ -58,12 +61,11 @@ func writeZipEntryMetadata(output io.Writer, entry *zip.File) error {
}
func
generateZipMetadata
(
output
io
.
Writer
,
archive
*
zip
.
Reader
)
error
{
// Write metadata header
if
err
:=
writeString
(
output
,
MetadataHeader
);
err
!=
nil
{
return
err
}
// Write empty error header
// Write empty error header
that we may need in the future
if
err
:=
writeString
(
output
,
"{}"
);
err
!=
nil
{
return
err
}
...
...
@@ -74,29 +76,17 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
// Add missing entries
for
_
,
entry
:=
range
archive
.
File
{
zipMap
[
entry
.
Name
]
=
entry
entryPath
:=
entry
.
Name
for
{
entryPath
=
path
.
Dir
(
entryPath
)
for
entryPath
:=
path
.
Dir
(
entry
.
Name
);
entryPath
!=
"."
&&
entryPath
!=
"/"
;
entryPath
=
path
.
Dir
(
entryPath
)
{
entryDir
:=
entryPath
+
"/"
if
entryPath
==
"."
||
entryPath
==
"/"
{
break
}
if
_
,
ok
:=
zipMap
[
entryDir
];
!
ok
{
var
missingHeader
zip
.
FileHeader
missingHeader
.
Name
=
entryDir
missingHeader
.
SetModTime
(
time
.
Now
())
missingHeader
.
SetMode
(
os
.
FileMode
(
uint32
(
0755
)))
missingEntry
:=
&
zip
.
File
{
FileHeader
:
missingHeader
}
zipMap
[
entryDir
]
=
missingEntry
zipMap
[
entryDir
]
=
nil
}
}
}
// Sort paths
var
sortedPaths
[]
string
sortedPaths
:=
make
([]
string
,
0
,
len
(
zipMap
))
for
path
,
_
:=
range
zipMap
{
sortedPaths
=
append
(
sortedPaths
,
path
)
}
...
...
@@ -104,7 +94,7 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
// Write all files
for
_
,
path
:=
range
sortedPaths
{
if
err
:=
writeZipEntryMetadata
(
output
,
zipMap
[
path
]);
err
!=
nil
{
if
err
:=
writeZipEntryMetadata
(
output
,
path
,
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