Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
35c4b5ec
Commit
35c4b5ec
authored
Nov 20, 2023
by
Jeffrey Morgan
Browse files
calculate hash separately from http request
parent
f24741ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
server/upload.go
server/upload.go
+13
-11
No files found.
server/upload.go
View file @
35c4b5ec
...
...
@@ -5,7 +5,6 @@ import (
"crypto/md5"
"errors"
"fmt"
"hash"
"io"
"log"
"math"
...
...
@@ -103,7 +102,7 @@ func (b *blobUpload) Prepare(ctx context.Context, requestURL *url.URL, opts *Reg
}
// set part.N to the current number of parts
b
.
Parts
=
append
(
b
.
Parts
,
blobUploadPart
{
blobUpload
:
b
,
N
:
len
(
b
.
Parts
),
Hash
:
md5
.
New
(),
Offset
:
offset
,
Size
:
size
})
b
.
Parts
=
append
(
b
.
Parts
,
blobUploadPart
{
blobUpload
:
b
,
N
:
len
(
b
.
Parts
),
Offset
:
offset
,
Size
:
size
})
offset
+=
size
}
...
...
@@ -178,8 +177,16 @@ func (b *blobUpload) Run(ctx context.Context, opts *RegistryOptions) {
requestURL
:=
<-
b
.
nextURL
var
sb
strings
.
Builder
// calculate md5 checksum and add it to the commit request
for
_
,
part
:=
range
b
.
Parts
{
sb
.
Write
(
part
.
Sum
(
nil
))
hash
:=
md5
.
New
()
if
_
,
err
:=
io
.
Copy
(
hash
,
io
.
NewSectionReader
(
b
.
file
,
part
.
Offset
,
part
.
Size
));
err
!=
nil
{
b
.
err
=
err
return
}
sb
.
Write
(
hash
.
Sum
(
nil
))
}
md5sum
:=
md5
.
Sum
([]
byte
(
sb
.
String
()))
...
...
@@ -334,13 +341,10 @@ func (b *blobUpload) Wait(ctx context.Context, fn func(api.ProgressResponse)) er
type
blobUploadPart
struct
{
// N is the part number
N
int
Offset
int64
Size
int64
hash
.
Hash
N
int
Offset
int64
Size
int64
written
int64
*
blobUpload
}
...
...
@@ -348,14 +352,12 @@ func (p *blobUploadPart) Write(b []byte) (n int, err error) {
n
=
len
(
b
)
p
.
written
+=
int64
(
n
)
p
.
Completed
.
Add
(
int64
(
n
))
p
.
Hash
.
Write
(
b
)
return
n
,
nil
}
func
(
p
*
blobUploadPart
)
Reset
()
{
p
.
Completed
.
Add
(
-
int64
(
p
.
written
))
p
.
written
=
0
p
.
Hash
.
Reset
()
}
func
uploadBlob
(
ctx
context
.
Context
,
mp
ModelPath
,
layer
*
Layer
,
opts
*
RegistryOptions
,
fn
func
(
api
.
ProgressResponse
))
error
{
...
...
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