Skip to content

Commit

Permalink
store: new function to retrieve underlying file
Browse files Browse the repository at this point in the history
add a new function to retrieve the underlying big data file for the
layers store.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Mar 5, 2024
1 parent 2a79830 commit bb59307
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,18 @@ func (r *layerStore) BigData(id, key string) (io.ReadCloser, error) {
return os.Open(r.datapath(layer.ID, key))
}

// Requires startReading or startWriting.
func (r *layerStore) BigDataFilePath(id, key string) (string, error) {
if key == "" {
return "", fmt.Errorf("can't retrieve layer big data value for empty name: %w", ErrInvalidBigDataName)
}
layer, ok := r.lookup(id)
if !ok {
return "", fmt.Errorf("locating layer with ID %q: %w", id, ErrLayerUnknown)
}
return r.datapath(layer.ID, key), nil
}

// Requires startWriting.
func (r *layerStore) SetBigData(id, key string, data io.Reader) error {
if !r.lockfile.IsReadWrite() {
Expand Down
30 changes: 30 additions & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ type roLayerBigDataStore interface {
// with this ID.
BigData(id, key string) (io.ReadCloser, error)

// BigDataFilePath returns the path to the underlying file, if the big data
// is backed by a file. Otherwise it returns the empty string.
BigDataFilePath(id, key string) (string, error)

// BigDataNames() returns a list of the names of previously-stored pieces of
// data.
BigDataNames(id string) ([]string, error)
Expand Down Expand Up @@ -440,6 +444,10 @@ type Store interface {
// associated with a layer.
LayerBigData(id, key string) (io.ReadCloser, error)

// LayerBigDataFile retrieves the backing file for the layers big data,
// when used.
LayerBigDataFilePath(id, key string) (string, error)

// SetLayerBigData stores a (possibly large) chunk of named data
// associated with a layer.
SetLayerBigData(id, key string, data io.Reader) error
Expand Down Expand Up @@ -2105,6 +2113,28 @@ func (s *store) LayerBigData(id, key string) (io.ReadCloser, error) {
return nil, fmt.Errorf("locating layer with ID %q: %w", id, ErrLayerUnknown)
}

// LayerBigDataFile retrieves the backing file for the layers big data,
// when used.
func (s *store) LayerBigDataFilePath(id, key string) (string, error) {
foundLayer := false
if res, done, err := readAllLayerStores(s, func(store roLayerStore) (string, bool, error) {
path, err := store.BigDataFilePath(id, key)
if err == nil {
return path, true, nil
}
if store.Exists(id) {
foundLayer = true
}
return "", false, nil
}); done {
return res, err
}
if foundLayer {
return "", fmt.Errorf("locating item named %q for layer with ID %q: %w", key, id, os.ErrNotExist)
}
return "", fmt.Errorf("locating layer with ID %q: %w", id, ErrLayerUnknown)
}

// SetLayerBigData stores a (possibly large) chunk of named data
// associated with a layer.
func (s *store) SetLayerBigData(id, key string, data io.Reader) error {
Expand Down

0 comments on commit bb59307

Please sign in to comment.