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
917bd610
Commit
917bd610
authored
Jan 26, 2024
by
Michael Yang
Browse files
refactor download run
parent
efe040f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
server/download.go
server/download.go
+11
-10
No files found.
server/download.go
View file @
917bd610
...
@@ -138,16 +138,13 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *r
...
@@ -138,16 +138,13 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *r
}
}
func
(
b
*
blobDownload
)
Run
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
opts
*
registryOptions
)
{
func
(
b
*
blobDownload
)
Run
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
opts
*
registryOptions
)
{
b
.
err
=
b
.
run
(
ctx
,
requestURL
,
opts
)
}
func
(
b
*
blobDownload
)
run
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
opts
*
registryOptions
)
error
{
defer
blobDownloadManager
.
Delete
(
b
.
Digest
)
defer
blobDownloadManager
.
Delete
(
b
.
Digest
)
ctx
,
b
.
CancelFunc
=
context
.
WithCancel
(
ctx
)
ctx
,
b
.
CancelFunc
=
context
.
WithCancel
(
ctx
)
file
,
err
:=
os
.
OpenFile
(
b
.
Name
+
"-partial"
,
os
.
O_CREATE
|
os
.
O_RDWR
,
0
o644
)
file
,
err
:=
os
.
OpenFile
(
b
.
Name
+
"-partial"
,
os
.
O_CREATE
|
os
.
O_RDWR
,
0
o644
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
b
.
err
=
err
return
}
}
defer
file
.
Close
()
defer
file
.
Close
()
...
@@ -188,26 +185,30 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *regis
...
@@ -188,26 +185,30 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *regis
}
}
if
err
:=
g
.
Wait
();
err
!=
nil
{
if
err
:=
g
.
Wait
();
err
!=
nil
{
return
err
b
.
err
=
err
return
}
}
// explicitly close the file so we can rename it
// explicitly close the file so we can rename it
if
err
:=
file
.
Close
();
err
!=
nil
{
if
err
:=
file
.
Close
();
err
!=
nil
{
return
err
b
.
err
=
err
return
}
}
for
i
:=
range
b
.
Parts
{
for
i
:=
range
b
.
Parts
{
if
err
:=
os
.
Remove
(
file
.
Name
()
+
"-"
+
strconv
.
Itoa
(
i
));
err
!=
nil
{
if
err
:=
os
.
Remove
(
file
.
Name
()
+
"-"
+
strconv
.
Itoa
(
i
));
err
!=
nil
{
return
err
b
.
err
=
err
return
}
}
}
}
if
err
:=
os
.
Rename
(
file
.
Name
(),
b
.
Name
);
err
!=
nil
{
if
err
:=
os
.
Rename
(
file
.
Name
(),
b
.
Name
);
err
!=
nil
{
return
err
b
.
err
=
err
return
}
}
b
.
done
=
true
b
.
done
=
true
return
nil
return
}
}
func
(
b
*
blobDownload
)
downloadChunk
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
w
io
.
Writer
,
part
*
blobDownloadPart
,
opts
*
registryOptions
)
error
{
func
(
b
*
blobDownload
)
downloadChunk
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
w
io
.
Writer
,
part
*
blobDownloadPart
,
opts
*
registryOptions
)
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