-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmountpoint.go
157 lines (128 loc) · 3.57 KB
/
mountpoint.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package digestfs
import (
"github.com/reiver/go-digestfs/driver"
"sync"
)
type MountPoint struct {
mutex sync.RWMutex
mountpoint digestfs_driver.MountPoint
}
func (dest *MountPoint) Mount(fstype string, params ...interface{}) error {
if nil == dest {
return errNilDestination
}
dest.mutex.Lock()
defer dest.mutex.Unlock()
if nil != dest.mountpoint {
return errMounted
}
mounter, err := digestfs_driver.Registry.Fetch(fstype)
if nil != err {
return err
}
if nil == mounter {
return errNilMounter
}
mountpoint, err := mounter.Mount(params...)
if nil != err {
return err
}
if nil == mountpoint {
return errNilMountPoint
}
dest.mountpoint = mountpoint
return nil
}
// Create creates new content at the MoutPoint.
//
// The value of ‘digest’ is in binary.
//
// The value of ‘digest’ is NOT a binary-to-text encoding such as hexadecimal, bas64, etc.
//
// So the value of ‘digest’ might be something such as:
//
// "\x00\x00\x00\x00\x00\x19\xd6\x68\x9c\x08\x5a\xe1\x65\x83\x1e\x93\x4f\xf7\x63\xae\x46\xa2\xa6\xc1\x72\xb3\xf1\xb6\x0a\x8c\xe2\x6f"
//
// Rather than any of these:
//
// "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" (not this)
//
// "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" (not this)
//
// "AAAAAAAZ1micCFrhZYMek0_3Y65GoqbBcrPxtgqM4m8" (not this)
//
// "00000000001kdxxHkC0H5AE1x5Hm1Ekm4ffVxmAE4xA2AxC1V2bmf1bx0AHCE2xf" (not this)
//
// "0r00000000001kdxxHkC0H5AE1x5Hm1Ekm4ffVxmAE4xA2AxC1V2bmf1bx0AHCE2xf" (not this)
func (receiver *MountPoint) Create(content []byte) (algorithm string, digest string, err error) {
if nil == receiver {
return "", "", errNilReceiver
}
receiver.mutex.Lock()
defer receiver.mutex.Unlock()
mountpoint := receiver.mountpoint
if nil == mountpoint {
return "", "", errNilMountPoint
}
return mountpoint.Create(content)
}
// Open returns content at the MountPoint.
//
// The value of ‘digest’ is in binary.
//
// The value of ‘digest’ is NOT a binary-to-text encoding such as hexadecimal, bas64, etc.
//
// So the value of ‘digest’ might be something such as:
//
// "\x00\x00\x00\x00\x00\x19\xd6\x68\x9c\x08\x5a\xe1\x65\x83\x1e\x93\x4f\xf7\x63\xae\x46\xa2\xa6\xc1\x72\xb3\xf1\xb6\x0a\x8c\xe2\x6f"
//
// Rather than any of these:
//
// "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" (not this)
//
// "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" (not this)
//
// "AAAAAAAZ1micCFrhZYMek0_3Y65GoqbBcrPxtgqM4m8" (not this)
//
// "00000000001kdxxHkC0H5AE1x5Hm1Ekm4ffVxmAE4xA2AxC1V2bmf1bx0AHCE2xf" (not this)
//
// "0r00000000001kdxxHkC0H5AE1x5Hm1Ekm4ffVxmAE4xA2AxC1V2bmf1bx0AHCE2xf" (not this)
func (receiver *MountPoint) Open(algorithm string, digest string) (Content, error) {
if nil == receiver {
return nil, errNilReceiver
}
receiver.mutex.RLock()
defer receiver.mutex.RUnlock()
mountpoint := receiver.mountpoint
if nil == mountpoint {
return nil, errNilMountPoint
}
return mountpoint.Open(algorithm, digest)
}
func (receiver *MountPoint) OpenLocation(location string) (Content, error) {
if nil == receiver {
return nil, errNilReceiver
}
receiver.mutex.RLock()
defer receiver.mutex.RUnlock()
mountpoint := receiver.mountpoint
if nil == mountpoint {
return nil, errNilMountPoint
}
return mountpoint.OpenLocation(location)
}
func (dest *MountPoint) Unmount() error {
if nil == dest {
return errNilDestination
}
dest.mutex.Lock()
defer dest.mutex.Unlock()
if nil != dest.mountpoint {
return nil
}
if err := dest.mountpoint.Unmount(); nil != err {
return err
}
dest.mountpoint = nil
return nil
}