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
a3737cbd
Commit
a3737cbd
authored
Nov 24, 2023
by
Michael Yang
Browse files
use NewLayer for CreateBlobHandler
parent
70a93057
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
24 deletions
+4
-24
server/routes.go
server/routes.go
+4
-24
No files found.
server/routes.go
View file @
a3737cbd
...
@@ -2,7 +2,6 @@ package server
...
@@ -2,7 +2,6 @@ package server
import
(
import
(
"context"
"context"
"crypto/sha256"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
...
@@ -862,37 +861,18 @@ func HeadBlobHandler(c *gin.Context) {
...
@@ -862,37 +861,18 @@ func HeadBlobHandler(c *gin.Context) {
}
}
func
CreateBlobHandler
(
c
*
gin
.
Context
)
{
func
CreateBlobHandler
(
c
*
gin
.
Context
)
{
targetPath
,
err
:=
GetBlobsPath
(
c
.
Param
(
"digest
"
)
)
layer
,
err
:=
NewLayer
(
c
.
Request
.
Body
,
"
"
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
hash
:=
sha256
.
New
()
if
layer
.
Digest
!=
c
.
Param
(
"digest"
)
{
temp
,
err
:=
os
.
CreateTemp
(
filepath
.
Dir
(
targetPath
),
c
.
Param
(
"digest"
)
+
"-"
)
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"digest mismatch, expected %q, got %q"
,
c
.
Param
(
"digest"
),
layer
.
Digest
)})
if
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
defer
temp
.
Close
()
defer
os
.
Remove
(
temp
.
Name
())
if
_
,
err
:=
io
.
Copy
(
temp
,
io
.
TeeReader
(
c
.
Request
.
Body
,
hash
));
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
if
fmt
.
Sprintf
(
"sha256:%x"
,
hash
.
Sum
(
nil
))
!=
c
.
Param
(
"digest"
)
{
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"digest does not match body"
})
return
}
if
err
:=
temp
.
Close
();
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
if
err
:=
os
.
Rename
(
temp
.
Name
(),
targetPath
);
err
!=
nil
{
if
_
,
err
:=
layer
.
Commit
(
);
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
c
.
AbortWithStatusJSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
...
...
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