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
e53bc57d
"tests/git@developer.sourcefind.cn:OpenDAS/pytorch3d.git" did not exist on "09a99f2e6d9164066ca78aaebe4c9a811ab5fbb9"
Commit
e53bc57d
authored
Sep 14, 2023
by
Michael Yang
Browse files
split uploadBlobChunked
parent
f0b398d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
53 deletions
+54
-53
server/upload.go
server/upload.go
+54
-53
No files found.
server/upload.go
View file @
e53bc57d
...
@@ -70,62 +70,23 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
...
@@ -70,62 +70,23 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
chunk
=
int64
(
chunkSize
)
chunk
=
int64
(
chunkSize
)
}
}
sectionReader
:=
io
.
NewSectionReader
(
f
,
int64
(
offset
),
chunk
)
resp
,
err
:=
uploadBlobChunk
(
ctx
,
requestURL
,
f
,
offset
,
chunk
,
regOpts
,
&
pw
)
if
err
!=
nil
{
var
errStatus
error
fn
(
api
.
ProgressResponse
{
for
try
:=
0
;
try
<
MaxRetries
;
try
++
{
Status
:
fmt
.
Sprintf
(
"error uploading limit: %v"
,
err
),
errStatus
=
nil
Digest
:
layer
.
Digest
,
Total
:
layer
.
Size
,
headers
:=
make
(
http
.
Header
)
Completed
:
int
(
offset
),
headers
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
})
headers
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
int
(
chunk
)))
headers
.
Set
(
"Content-Range"
,
fmt
.
Sprintf
(
"%d-%d"
,
offset
,
offset
+
sectionReader
.
Size
()
-
1
))
resp
,
err
:=
makeRequest
(
ctx
,
"PATCH"
,
requestURL
,
headers
,
io
.
TeeReader
(
sectionReader
,
&
pw
),
regOpts
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
fn
(
api
.
ProgressResponse
{
Status
:
fmt
.
Sprintf
(
"error uploading chunk: %v"
,
err
),
Digest
:
layer
.
Digest
,
Total
:
layer
.
Size
,
Completed
:
int
(
offset
),
})
return
err
}
defer
resp
.
Body
.
Close
()
switch
{
case
resp
.
StatusCode
==
http
.
StatusUnauthorized
:
errStatus
=
errors
.
New
(
"unauthorized"
)
auth
:=
resp
.
Header
.
Get
(
"www-authenticate"
)
authRedir
:=
ParseAuthRedirectString
(
auth
)
token
,
err
:=
getAuthToken
(
ctx
,
authRedir
)
if
err
!=
nil
{
return
err
}
regOpts
.
Token
=
token
pw
.
completed
=
int
(
offset
)
sectionReader
=
io
.
NewSectionReader
(
f
,
offset
,
chunk
)
continue
case
resp
.
StatusCode
>=
http
.
StatusBadRequest
:
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
fmt
.
Errorf
(
"on upload registry responded with code %d: %s"
,
resp
.
StatusCode
,
body
)
}
offset
+=
sectionReader
.
Size
()
requestURL
,
err
=
url
.
Parse
(
resp
.
Header
.
Get
(
"Location"
))
if
err
!=
nil
{
return
err
}
break
}
}
if
errStatus
!=
nil
{
offset
+=
chunk
return
fmt
.
Errorf
(
"max retries exceeded: %w"
,
errStatus
)
location
,
err
:=
resp
.
Location
()
if
err
!=
nil
{
return
err
}
}
requestURL
=
location
}
}
values
:=
requestURL
.
Query
()
values
:=
requestURL
.
Query
()
...
@@ -151,6 +112,46 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
...
@@ -151,6 +112,46 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
return
nil
return
nil
}
}
func
uploadBlobChunk
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
r
io
.
ReaderAt
,
offset
,
limit
int64
,
opts
*
RegistryOptions
,
pw
*
ProgressWriter
)
(
*
http
.
Response
,
error
)
{
sectionReader
:=
io
.
NewSectionReader
(
r
,
int64
(
offset
),
limit
)
headers
:=
make
(
http
.
Header
)
headers
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
headers
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
int
(
limit
)))
headers
.
Set
(
"Content-Range"
,
fmt
.
Sprintf
(
"%d-%d"
,
offset
,
offset
+
sectionReader
.
Size
()
-
1
))
for
try
:=
0
;
try
<
MaxRetries
;
try
++
{
resp
,
err
:=
makeRequest
(
ctx
,
"PATCH"
,
requestURL
,
headers
,
io
.
TeeReader
(
sectionReader
,
pw
),
opts
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
switch
{
case
resp
.
StatusCode
==
http
.
StatusUnauthorized
:
auth
:=
resp
.
Header
.
Get
(
"www-authenticate"
)
authRedir
:=
ParseAuthRedirectString
(
auth
)
token
,
err
:=
getAuthToken
(
ctx
,
authRedir
)
if
err
!=
nil
{
return
nil
,
err
}
opts
.
Token
=
token
pw
.
completed
=
int
(
offset
)
sectionReader
=
io
.
NewSectionReader
(
r
,
offset
,
limit
)
continue
case
resp
.
StatusCode
>=
http
.
StatusBadRequest
:
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
nil
,
fmt
.
Errorf
(
"on upload registry responded with code %d: %s"
,
resp
.
StatusCode
,
body
)
}
return
resp
,
nil
}
return
nil
,
fmt
.
Errorf
(
"max retries exceeded"
)
}
type
ProgressWriter
struct
{
type
ProgressWriter
struct
{
status
string
status
string
digest
string
digest
string
...
...
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