-
Notifications
You must be signed in to change notification settings - Fork 162
/
add_blob.go
38 lines (29 loc) · 902 Bytes
/
add_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
package cmd
import (
"os"
boshreldir "github.com/cloudfoundry/bosh-cli/releasedir"
boshui "github.com/cloudfoundry/bosh-cli/ui"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type AddBlobCmd struct {
blobsDir boshreldir.BlobsDir
fs boshsys.FileSystem
ui boshui.UI
}
func NewAddBlobCmd(blobsDir boshreldir.BlobsDir, fs boshsys.FileSystem, ui boshui.UI) AddBlobCmd {
return AddBlobCmd{blobsDir: blobsDir, fs: fs, ui: ui}
}
func (c AddBlobCmd) Run(opts AddBlobOpts) error {
file, err := c.fs.OpenFile(opts.Args.Path, os.O_RDONLY, 0)
if err != nil {
return bosherr.WrapErrorf(err, "Opening blob")
}
defer file.Close()
blob, err := c.blobsDir.TrackBlob(opts.Args.BlobsPath, file)
if err != nil {
return bosherr.WrapErrorf(err, "Tracking blob")
}
c.ui.PrintLinef("Added blob '%s'", blob.Path)
return nil
}