Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Commit fe8b54f

Browse files
committed
fix refcount
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
1 parent acb66a4 commit fe8b54f

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

main.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ func (d *sshfsDriver) Remove(r volume.Request) volume.Response {
115115
return responseError(fmt.Sprintf("volume %s not found", r.Name))
116116
}
117117

118-
if v.connections == 0 {
119-
if err := os.RemoveAll(v.Mountpoint); err != nil {
120-
return responseError(err.Error())
121-
}
122-
delete(d.volumes, r.Name)
123-
d.saveState()
124-
return volume.Response{}
118+
if v.connections != 0 {
119+
return responseError(fmt.Sprintf("volume %s is currently used by a container", r.Name))
125120
}
126-
return responseError(fmt.Sprintf("volume %s is currently used by a container", r.Name))
121+
if err := os.RemoveAll(v.Mountpoint); err != nil {
122+
return responseError(err.Error())
123+
}
124+
delete(d.volumes, r.Name)
125+
d.saveState()
126+
return volume.Response{}
127127
}
128128

129129
func (d *sshfsDriver) Path(r volume.Request) volume.Response {
@@ -151,28 +151,27 @@ func (d *sshfsDriver) Mount(r volume.MountRequest) volume.Response {
151151
return responseError(fmt.Sprintf("volume %s not found", r.Name))
152152
}
153153

154-
if v.connections > 0 {
155-
v.connections++
156-
return volume.Response{Mountpoint: v.Mountpoint}
157-
}
158-
159-
fi, err := os.Lstat(v.Mountpoint)
160-
if os.IsNotExist(err) {
161-
if err := os.MkdirAll(v.Mountpoint, 0755); err != nil {
154+
if v.connections == 0 {
155+
fi, err := os.Lstat(v.Mountpoint)
156+
if os.IsNotExist(err) {
157+
if err := os.MkdirAll(v.Mountpoint, 0755); err != nil {
158+
return responseError(err.Error())
159+
}
160+
} else if err != nil {
162161
return responseError(err.Error())
163162
}
164-
} else if err != nil {
165-
return responseError(err.Error())
166-
}
167163

168-
if fi != nil && !fi.IsDir() {
169-
return responseError(fmt.Sprintf("%v already exist and it's not a directory", v.Mountpoint))
170-
}
164+
if fi != nil && !fi.IsDir() {
165+
return responseError(fmt.Sprintf("%v already exist and it's not a directory", v.Mountpoint))
166+
}
171167

172-
if err := d.mountVolume(v); err != nil {
173-
return responseError(err.Error())
168+
if err := d.mountVolume(v); err != nil {
169+
return responseError(err.Error())
170+
}
174171
}
175172

173+
v.connections++
174+
176175
return volume.Response{Mountpoint: v.Mountpoint}
177176
}
178177

@@ -185,13 +184,14 @@ func (d *sshfsDriver) Unmount(r volume.UnmountRequest) volume.Response {
185184
if !ok {
186185
return responseError(fmt.Sprintf("volume %s not found", r.Name))
187186
}
188-
if v.connections <= 1 {
187+
188+
v.connections--
189+
190+
if v.connections <= 0 {
189191
if err := d.unmountVolume(v.Mountpoint); err != nil {
190192
return responseError(err.Error())
191193
}
192194
v.connections = 0
193-
} else {
194-
v.connections--
195195
}
196196

197197
return volume.Response{}

0 commit comments

Comments
 (0)