Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 2 additions & 44 deletions pkg/v1/layout/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package layout

import (
"fmt"
"io"
"os"

Expand All @@ -24,56 +23,15 @@ import (

// Blob returns a blob with the given hash from the Path.
func (l Path) Blob(h v1.Hash) (io.ReadCloser, error) {
return l.openBlob(h)
return os.Open(l.blobPath(h))
}

// Bytes is a convenience function to return a blob from the Path as
// a byte slice.
func (l Path) Bytes(h v1.Hash) ([]byte, error) {
f, err := l.openBlob(h)
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
return os.ReadFile(l.blobPath(h))
}

func (l Path) blobPath(h v1.Hash) string {
return l.path("blobs", h.Algorithm, h.Hex)
}

func (l Path) openBlob(h v1.Hash) (*os.File, error) {
p := l.blobPath(h)
info, err := os.Lstat(p)
if err != nil {
return nil, err
}
if info.Mode()&os.ModeSymlink != 0 {
return nil, fmt.Errorf("layout blob %s is a symlink", h)
}
if !info.Mode().IsRegular() {
return nil, fmt.Errorf("layout blob %s is not a regular file", h)
}
f, err := os.Open(p)
if err != nil {
return nil, err
}
closeFile := true
defer func() {
if closeFile {
f.Close()
}
}()
stat, err := f.Stat()
if err != nil {
return nil, err
}
if !stat.Mode().IsRegular() {
return nil, fmt.Errorf("layout blob %s is not a regular file", h)
}
if !os.SameFile(info, stat) {
return nil, fmt.Errorf("layout blob %s changed while opening", h)
}
closeFile = false
return f, nil
}
69 changes: 0 additions & 69 deletions pkg/v1/layout/blob_test.go

This file was deleted.

Loading