forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_blob.go
58 lines (49 loc) · 1.35 KB
/
local_blob.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
package blobstore
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
// LocalBlob represents a local copy of a blob retrieved from the blobstore
type LocalBlob interface {
// Path returns the path to the local copy of the blob
Path() string
// Delete removes the local copy of the blob (does not effect the blobstore)
Delete() error
// DeleteSilently removes the local copy of the blob (does not effect the blobstore), logging instead of returning an error.
DeleteSilently()
}
type localBlob struct {
path string
fs boshsys.FileSystem
logger boshlog.Logger
logTag string
}
func NewLocalBlob(path string, fs boshsys.FileSystem, logger boshlog.Logger) LocalBlob {
return &localBlob{
path: path,
fs: fs,
logger: logger,
logTag: "localBlob",
}
}
func (b *localBlob) Path() string {
return b.path
}
func (b *localBlob) Delete() error {
err := b.fs.RemoveAll(b.path)
if err != nil {
return bosherr.WrapErrorf(err, "Deleting local blob '%s'", b.path)
}
return nil
}
func (b *localBlob) DeleteSilently() {
err := b.Delete()
if err != nil {
b.logger.Error(b.logTag, "Failed to delete local blob: %s", err.Error())
}
}
func (b *localBlob) String() string {
return fmt.Sprintf("localBlob{path: '%s'}", b.path)
}