-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbase.go
More file actions
62 lines (51 loc) · 1.73 KB
/
base.go
File metadata and controls
62 lines (51 loc) · 1.73 KB
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
package base
import storagedriver "github.com/deis/builder/pkg/storage/driver"
// Base provides a wrapper around a storagedriver implementation that provides
// common path and bounds checking.
type Base struct {
storagedriver.StorageDriver
}
// Format errors received from the storage driver
func (base *Base) setDriverName(e error) error {
switch actual := e.(type) {
case nil:
return nil
case storagedriver.ErrUnsupportedMethod:
actual.DriverName = base.StorageDriver.Name()
return actual
case storagedriver.PathNotFoundError:
actual.DriverName = base.StorageDriver.Name()
return actual
case storagedriver.InvalidPathError:
actual.DriverName = base.StorageDriver.Name()
return actual
case storagedriver.InvalidOffsetError:
actual.DriverName = base.StorageDriver.Name()
return actual
default:
storageError := storagedriver.Error{
DriverName: base.StorageDriver.Name(),
Enclosed: e,
}
return storageError
}
}
// CheckConnectionStatus wraps CheckConnectionStatus of underlying storage driver.
func (base *Base) CheckConnectionStatus() (bool, error) {
b, e := base.StorageDriver.CheckConnectionStatus()
return b, e
}
// PutContent wraps PutContent of underlying storage driver.
func (base *Base) PutContent(path string, content []byte) error {
return base.setDriverName(base.StorageDriver.PutContent(path, content))
}
// GetContent wraps GetContent of underlying storage driver.
func (base *Base) GetContent(path string) ([]byte, error) {
b, e := base.StorageDriver.GetContent(path)
return b, base.setDriverName(e)
}
// Stat wraps Stat of underlying storage driver.
func (base *Base) Stat(path string) (storagedriver.FileInfo, error) {
fi, e := base.StorageDriver.Stat(path)
return fi, base.setDriverName(e)
}