daemon/delete.go: use less confusing naming of functions
| ... | ... |
@@ -41,34 +41,10 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 | 43 |
if config.RemoveLink {
|
| 44 |
- name, err := GetFullContainerName(name) |
|
| 45 |
- if err != nil {
|
|
| 46 |
- return err |
|
| 47 |
- } |
|
| 48 |
- parent, n := path.Split(name) |
|
| 49 |
- if parent == "/" {
|
|
| 50 |
- return derr.ErrorCodeDefaultName |
|
| 51 |
- } |
|
| 52 |
- pe := daemon.containerGraph().Get(parent) |
|
| 53 |
- if pe == nil {
|
|
| 54 |
- return derr.ErrorCodeNoParent.WithArgs(parent, name) |
|
| 55 |
- } |
|
| 56 |
- |
|
| 57 |
- if err := daemon.containerGraph().Delete(name); err != nil {
|
|
| 58 |
- return err |
|
| 59 |
- } |
|
| 60 |
- |
|
| 61 |
- parentContainer, _ := daemon.Get(pe.ID()) |
|
| 62 |
- if parentContainer != nil {
|
|
| 63 |
- if err := daemon.updateNetwork(parentContainer); err != nil {
|
|
| 64 |
- logrus.Debugf("Could not update network to remove link %s: %v", n, err)
|
|
| 65 |
- } |
|
| 66 |
- } |
|
| 67 |
- |
|
| 68 |
- return nil |
|
| 44 |
+ return daemon.rmLink(name) |
|
| 69 | 45 |
} |
| 70 | 46 |
|
| 71 |
- if err := daemon.rm(container, config.ForceRemove); err != nil {
|
|
| 47 |
+ if err := daemon.cleanupContainer(container, config.ForceRemove); err != nil {
|
|
| 72 | 48 |
// return derr.ErrorCodeCantDestroy.WithArgs(name, utils.GetErrorMessage(err)) |
| 73 | 49 |
return err |
| 74 | 50 |
} |
| ... | ... |
@@ -80,8 +56,38 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error |
| 80 | 80 |
return nil |
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 |
-// Destroy unregisters a container from the daemon and cleanly removes its contents from the filesystem. |
|
| 84 |
-func (daemon *Daemon) rm(container *Container, forceRemove bool) (err error) {
|
|
| 83 |
+// rmLink removes link by name from other containers |
|
| 84 |
+func (daemon *Daemon) rmLink(name string) error {
|
|
| 85 |
+ name, err := GetFullContainerName(name) |
|
| 86 |
+ if err != nil {
|
|
| 87 |
+ return err |
|
| 88 |
+ } |
|
| 89 |
+ parent, n := path.Split(name) |
|
| 90 |
+ if parent == "/" {
|
|
| 91 |
+ return derr.ErrorCodeDefaultName |
|
| 92 |
+ } |
|
| 93 |
+ pe := daemon.containerGraph().Get(parent) |
|
| 94 |
+ if pe == nil {
|
|
| 95 |
+ return derr.ErrorCodeNoParent.WithArgs(parent, name) |
|
| 96 |
+ } |
|
| 97 |
+ |
|
| 98 |
+ if err := daemon.containerGraph().Delete(name); err != nil {
|
|
| 99 |
+ return err |
|
| 100 |
+ } |
|
| 101 |
+ |
|
| 102 |
+ parentContainer, _ := daemon.Get(pe.ID()) |
|
| 103 |
+ if parentContainer != nil {
|
|
| 104 |
+ if err := daemon.updateNetwork(parentContainer); err != nil {
|
|
| 105 |
+ logrus.Debugf("Could not update network to remove link %s: %v", n, err)
|
|
| 106 |
+ } |
|
| 107 |
+ } |
|
| 108 |
+ |
|
| 109 |
+ return nil |
|
| 110 |
+} |
|
| 111 |
+ |
|
| 112 |
+// cleanupContainer unregisters a container from the daemon, stops stats |
|
| 113 |
+// collection and cleanly removes contents and metadata from the filesystem. |
|
| 114 |
+func (daemon *Daemon) cleanupContainer(container *Container, forceRemove bool) (err error) {
|
|
| 85 | 115 |
if container.IsRunning() {
|
| 86 | 116 |
if !forceRemove {
|
| 87 | 117 |
return derr.ErrorCodeRmRunning |