forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cascading_blobstore.go
64 lines (49 loc) · 1.59 KB
/
cascading_blobstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package blobstore
import (
boshUtilsBlobStore "github.com/cloudfoundry/bosh-utils/blobstore"
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
const logTag = "cascadingBlobstore"
type cascadingBlobstore struct {
innerBlobstore boshUtilsBlobStore.DigestBlobstore
blobManager boshUtilsBlobStore.BlobManagerInterface
logger boshlog.Logger
}
func NewCascadingBlobstore(
innerBlobstore boshUtilsBlobStore.DigestBlobstore,
blobManager boshUtilsBlobStore.BlobManagerInterface,
logger boshlog.Logger) boshUtilsBlobStore.DigestBlobstore {
return cascadingBlobstore{
innerBlobstore: innerBlobstore,
blobManager: blobManager,
logger: logger,
}
}
func (b cascadingBlobstore) Get(blobID string, digest boshcrypto.Digest) (string, error) {
if b.blobManager.BlobExists(blobID) {
blobPath, err := b.blobManager.GetPath(blobID, digest)
if err != nil {
return "", err
}
b.logger.Debug(logTag, "Found blob with BlobManager. BlobID: %s", blobID)
return blobPath, nil
}
return b.innerBlobstore.Get(blobID, digest)
}
func (b cascadingBlobstore) CleanUp(fileName string) error {
return b.innerBlobstore.CleanUp(fileName)
}
func (b cascadingBlobstore) Create(fileName string) (string, boshcrypto.MultipleDigest, error) {
return b.innerBlobstore.Create(fileName)
}
func (b cascadingBlobstore) Validate() error {
return b.innerBlobstore.Validate()
}
func (b cascadingBlobstore) Delete(blobID string) error {
err := b.blobManager.Delete(blobID)
if err != nil {
return err
}
return b.innerBlobstore.Delete(blobID)
}