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
2666d3c2
Commit
2666d3c2
authored
Jul 12, 2023
by
Michael Yang
Browse files
fix pull race
parent
5571ed52
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
server/models.go
server/models.go
+1
-13
server/routes.go
server/routes.go
+18
-0
No files found.
server/models.go
View file @
2666d3c2
...
@@ -76,22 +76,10 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
...
@@ -76,22 +76,10 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
return
fmt
.
Errorf
(
"failed to download model: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to download model: %w"
,
err
)
}
}
// check if completed file exists
fi
,
err
:=
os
.
Stat
(
model
.
FullName
())
switch
{
case
errors
.
Is
(
err
,
os
.
ErrNotExist
)
:
// noop, file doesn't exist so create it
case
err
!=
nil
:
return
fmt
.
Errorf
(
"stat: %w"
,
err
)
default
:
fn
(
fi
.
Size
(),
fi
.
Size
())
return
nil
}
var
size
int64
var
size
int64
// completed file doesn't exist, check partial file
// completed file doesn't exist, check partial file
fi
,
err
=
os
.
Stat
(
model
.
TempFile
())
fi
,
err
:
=
os
.
Stat
(
model
.
TempFile
())
switch
{
switch
{
case
errors
.
Is
(
err
,
os
.
ErrNotExist
)
:
case
errors
.
Is
(
err
,
os
.
ErrNotExist
)
:
// noop, file doesn't exist so create it
// noop, file doesn't exist so create it
...
...
server/routes.go
View file @
2666d3c2
...
@@ -105,6 +105,24 @@ func pull(c *gin.Context) {
...
@@ -105,6 +105,24 @@ func pull(c *gin.Context) {
return
return
}
}
// check if completed file exists
fi
,
err
:=
os
.
Stat
(
remote
.
FullName
())
switch
{
case
errors
.
Is
(
err
,
os
.
ErrNotExist
)
:
// noop, file doesn't exist so create it
case
err
!=
nil
:
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
default
:
c
.
JSON
(
http
.
StatusOK
,
api
.
PullProgress
{
Total
:
fi
.
Size
(),
Completed
:
fi
.
Size
(),
Percent
:
100
,
})
return
}
ch
:=
make
(
chan
any
)
ch
:=
make
(
chan
any
)
go
stream
(
c
,
ch
)
go
stream
(
c
,
ch
)
...
...
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