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
a2055a1e
Commit
a2055a1e
authored
Oct 09, 2023
by
Michael Yang
Browse files
update download
parent
b599946b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
server/download.go
server/download.go
+10
-7
No files found.
server/download.go
View file @
a2055a1e
...
@@ -30,6 +30,7 @@ type blobDownload struct {
...
@@ -30,6 +30,7 @@ type blobDownload struct {
Total
int64
Total
int64
Completed
atomic
.
Int64
Completed
atomic
.
Int64
done
bool
Parts
[]
*
blobDownloadPart
Parts
[]
*
blobDownloadPart
...
@@ -124,7 +125,7 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *Regis
...
@@ -124,7 +125,7 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *Regis
file
.
Truncate
(
b
.
Total
)
file
.
Truncate
(
b
.
Total
)
g
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
g
,
_
:=
errgroup
.
WithContext
(
ctx
)
// TODO(mxyng): download concurrency should be configurable
// TODO(mxyng): download concurrency should be configurable
g
.
SetLimit
(
64
)
g
.
SetLimit
(
64
)
for
i
:=
range
b
.
Parts
{
for
i
:=
range
b
.
Parts
{
...
@@ -168,7 +169,12 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *Regis
...
@@ -168,7 +169,12 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *Regis
}
}
}
}
return
os
.
Rename
(
file
.
Name
(),
b
.
Name
)
if
err
:=
os
.
Rename
(
file
.
Name
(),
b
.
Name
);
err
!=
nil
{
return
err
}
b
.
done
=
true
return
nil
}
}
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
{
...
@@ -267,13 +273,10 @@ func (b *blobDownload) Wait(ctx context.Context, fn func(api.ProgressResponse))
...
@@ -267,13 +273,10 @@ func (b *blobDownload) Wait(ctx context.Context, fn func(api.ProgressResponse))
Completed
:
b
.
Completed
.
Load
(),
Completed
:
b
.
Completed
.
Load
(),
})
})
if
b
.
Completed
.
Load
()
>=
b
.
Total
{
if
b
.
done
{
// wait for the file to get renamed
if
_
,
err
:=
os
.
Stat
(
b
.
Name
);
err
==
nil
{
return
nil
return
nil
}
}
}
}
}
}
}
type
downloadOpts
struct
{
type
downloadOpts
struct
{
...
...
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