fix pull race

This commit is contained in:
Michael Yang
2023-07-12 19:07:15 -07:00
parent 5571ed5248
commit 2666d3c206
2 changed files with 19 additions and 13 deletions

View File

@@ -105,6 +105,24 @@ func pull(c *gin.Context) {
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)
go stream(c, ch)