Debian Codegraph @

storage/multi_storage.go

raw
1 package storage
2
3 import (
4 "io"
5
6 "github.com/git-lfs/gitobj/v2/errors"
7 )
8
9 // Storage implements an interface for reading, but not writing, objects in an
10 // object database.
11 type multiStorage struct {
12 impls []Storage
13 }
14
15 func MultiStorage(args ...Storage) Storage {
16 return &multiStorage{impls: args}
17 }
18
19 // Open returns a handle on an existing object keyed by the given object
20 // ID. It returns an error if that file does not already exist.
21 func (m *multiStorage) Open(oid []byte) (f io.ReadCloser, err error) {
22 for _, s := range m.impls {
23 f, err := s.Open(oid)
24 if err != nil {
25 if errors.IsNoSuchObject(err) {
26 continue
27 }
28 return nil, err
29 }
30 if s.IsCompressed() {
31 return newDecompressingReadCloser(f)
32 }
33 return f, nil
34 }
35 return nil, errors.NoSuchObject(oid)
36 }
37
38 // Close closes the filesystem, after which no more operations are
39 // allowed.
40 func (m *multiStorage) Close() error {
41 for _, s := range m.impls {
42 if err := s.Close(); err != nil {
43 return err
44 }
45 }
46 return nil
47 }
48
49 // Compressed indicates whether data read from this storage source will
50 // be zlib-compressed.
51 func (m *multiStorage) IsCompressed() bool {
52 // To ensure we can read from any Storage type, we automatically
53 // decompress items if they need it.
54 return false
55 }