Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
ea064d24
Commit
ea064d24
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
also return source file hash on api call
parent
dc85a595
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
importer/fetch.go
+28
-14
28 additions, 14 deletions
importer/fetch.go
importer/types.go
+3
-2
3 additions, 2 deletions
importer/types.go
with
31 additions
and
16 deletions
importer/fetch.go
+
28
−
14
View file @
ea064d24
...
...
@@ -25,12 +25,13 @@
package
importer
import
(
"crypto/sha256"
"encoding/hex"
"encoding/base64"
"io"
"sync/atomic"
"time"
"unsafe"
"golang.org/x/crypto/blake2b"
)
type
devNull
uint64
...
...
@@ -81,6 +82,11 @@ func (pw *progressWriter) Write(p []byte) (n int, err error) {
return
}
type
copyResult
struct
{
err
error
hash
string
}
func
(
job
*
Job
)
fetch
()
error
{
job
.
Progress
.
set
(
StepFetching
,
0
)
...
...
@@ -100,31 +106,39 @@ func (job *Job) fetch() error {
return
err
}
done
:=
make
(
chan
error
)
done
:=
make
(
chan
copyResult
)
go
func
()
{
hash
:=
sha256
.
New
()
hash
,
err
:=
blake2b
.
New256
(
nil
)
if
err
!=
nil
{
panic
(
"created hash function failed: "
+
err
.
Error
())
}
src
:=
io
.
TeeReader
(
job
.
source
.
r
,
hash
)
written
,
err
:=
io
.
Copy
(
&
progressWriter
{
job
,
0
,
conv
},
src
)
hashHex
:=
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
job
.
im
.
dbgLog
.
Printf
(
"fetch(): done copying %d bytes from source (SHA256: %s)"
,
written
,
hashHex
)
job
.
im
.
store
.
UpdateFileSourceHash
(
job
.
Group
,
job
.
ID
,
"sha256:"
+
hashHex
)
done
<-
err
if
err
!=
nil
{
done
<-
copyResult
{
err
,
""
}
return
}
hashStr
:=
"blake2b_256:"
+
base64
.
URLEncoding
.
EncodeToString
(
hash
.
Sum
(
nil
))
job
.
im
.
dbgLog
.
Printf
(
"fetch(): done copying %d bytes from source (%s)"
,
written
,
hashStr
)
_
,
err
=
job
.
im
.
store
.
UpdateFileSourceHash
(
job
.
Group
,
job
.
ID
,
hashStr
)
done
<-
copyResult
{
err
,
hashStr
}
}()
var
res
copyResult
select
{
case
<-
job
.
ctx
.
Done
()
:
return
job
.
ctx
.
Err
()
case
err
=
<-
done
:
case
res
=
<-
done
:
}
conv
.
Close
()
corr
,
convLog
,
convE
rr
:=
conv
.
Wait
()
job
.
im
.
dbgLog
.
Printf
(
"fetch(): converter returned: %f db, %v"
,
corr
,
convE
rr
)
if
convE
rr
!
=
nil
{
err
=
convE
rr
corr
,
convLog
,
e
rr
:=
conv
.
Wait
()
job
.
im
.
dbgLog
.
Printf
(
"fetch(): converter returned: %f db, %v"
,
corr
,
e
rr
)
if
e
rr
=
=
nil
{
err
=
res
.
e
rr
}
job
.
Progress
.
set
(
StepFetching
,
1
)
job
.
source
.
done
<-
&
JobSourceResult
{
err
,
convLog
}
job
.
source
.
done
<-
&
JobSourceResult
{
err
,
res
.
hash
,
convLog
}
return
err
}
This diff is collapsed.
Click to expand it.
importer/types.go
+
3
−
2
View file @
ea064d24
...
...
@@ -75,8 +75,9 @@ func (s *SourceURL) UnmarshalText(data []byte) (err error) {
//******* Source
type
JobSourceResult
struct
{
Err
error
`json:"error,omitempty"`
Log
[]
string
`json:"log"`
Err
error
`json:"error,omitempty"`
Hash
string
`json:"hash,omitempty"`
Log
[]
string
`json:"log"`
}
func
(
r
*
JobSourceResult
)
Error
()
string
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment