mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
compliance: be compliant with dist-spec compliance tests
dist-spec compliance tests are now becoming a part of dist-spec repo itself - we want to be compliant pkg/api/regex.go: * revert uppercasing in repository names pkg/api/routes.go: * ListTags() should support the URL params 'n' and 'last' for pagination * s/uuid/session_id/g to use the dist-spec's naming * Fix off-by-one error in GetBlobUpload()'s http response "Range" header * DeleteManifest() success status code is 202 * Fix PatchBlobUpload() to account for "streamed" use case where neither "Content-Length" nor "Content-Range" headers are set pkg/storage/storage.go: * Add a "streamed" version of PutBlobChunk() called PutBlobChunkStreamed() pkg/compliance/v1_0_0/check.go: * fix unit tests to account for changed response status codes
This commit is contained in:
+45
-1
@@ -243,6 +243,11 @@ func (is *ImageStore) GetImageManifest(repo string, reference string) ([]byte, s
|
||||
|
||||
if err != nil {
|
||||
is.log.Error().Err(err).Str("dir", dir).Msg("failed to read index.json")
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return nil, "", "", errors.ErrRepoNotFound
|
||||
}
|
||||
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
@@ -286,8 +291,14 @@ func (is *ImageStore) GetImageManifest(repo string, reference string) ([]byte, s
|
||||
p = path.Join(p, digest.Encoded())
|
||||
|
||||
buf, err = ioutil.ReadFile(p)
|
||||
|
||||
if err != nil {
|
||||
is.log.Error().Err(err).Str("blob", p).Msg("failed to read manifest")
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return nil, "", "", errors.ErrManifestNotFound
|
||||
}
|
||||
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
@@ -548,6 +559,39 @@ func (is *ImageStore) GetBlobUpload(repo string, uuid string) (int64, error) {
|
||||
return fi.Size(), nil
|
||||
}
|
||||
|
||||
// PutBlobChunkStreamed appends another chunk of data to the specified blob. It returns
|
||||
// the number of actual bytes to the blob.
|
||||
func (is *ImageStore) PutBlobChunkStreamed(repo string, uuid string, body io.Reader) (int64, error) {
|
||||
if err := is.InitRepo(repo); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
blobUploadPath := is.BlobUploadPath(repo, uuid)
|
||||
|
||||
_, err := os.Stat(blobUploadPath)
|
||||
if err != nil {
|
||||
return -1, errors.ErrUploadNotFound
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(
|
||||
blobUploadPath,
|
||||
os.O_WRONLY|os.O_CREATE,
|
||||
0600,
|
||||
)
|
||||
if err != nil {
|
||||
is.log.Fatal().Err(err).Msg("failed to open file")
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := file.Seek(0, io.SeekEnd); err != nil {
|
||||
is.log.Fatal().Err(err).Msg("failed to seek file")
|
||||
}
|
||||
|
||||
n, err := io.Copy(file, body)
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
// PutBlobChunk writes another chunk of data to the specified blob. It returns
|
||||
// the number of actual bytes to the blob.
|
||||
func (is *ImageStore) PutBlobChunk(repo string, uuid string, from int64, to int64,
|
||||
@@ -579,7 +623,7 @@ func (is *ImageStore) PutBlobChunk(repo string, uuid string, from int64, to int6
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := file.Seek(from, 0); err != nil {
|
||||
if _, err := file.Seek(from, io.SeekStart); err != nil {
|
||||
is.log.Fatal().Err(err).Msg("failed to seek file")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user