Skip to content

Commit

Permalink
Use interface for removal to keep context
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Mar 26, 2018
1 parent e005667 commit 7a90a1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ func (d *Driver) GetMounts() map[string]driver.Mount {
return mi
}

//RemoveVolume remove a volume of driver
func (d *Driver) RemoveVolume(id string) error {
delete(d.Volumes, id)
return nil
}

//RemoveMount remove a mount of driver
func (d *Driver) RemoveMount(id string) error {
delete(d.Mounts, id)
return nil
}

//GetLock list lock of driver
func (d *Driver) GetLock() *sync.RWMutex {
return &d.Lock
Expand Down
10 changes: 8 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
type Driver interface {
GetLock() *sync.RWMutex
GetVolumes() map[string]Volume
RemoveVolume(string) error
GetMounts() map[string]Mount
RemoveMount(string) error
SaveConfig() error
RunCmd(string) error
}
Expand Down Expand Up @@ -96,9 +98,13 @@ func Remove(d Driver, vName string) error {
if err := os.Remove(m.GetPath()); err != nil && !strings.Contains(err.Error(), "no such file or directory") {
return err
}
delete(d.GetMounts(), v.GetMount())
if err := d.RemoveMount(v.GetMount()); err != nil {
return err
}
}
if err := d.RemoveVolume(vName); err != nil {
return err
}
delete(d.GetVolumes(), vName)
return d.SaveConfig()
}
return fmt.Errorf("volume %s is currently used by a container", vName)
Expand Down

0 comments on commit 7a90a1c

Please sign in to comment.