UnmountRecursive unmounts the target and all mounts underneath, starting with the deepest mount first.
(target string, flags int)
| 31 | // UnmountRecursive unmounts the target and all mounts underneath, starting |
| 32 | // with the deepest mount first. |
| 33 | func UnmountRecursive(target string, flags int) error { |
| 34 | if target == "" { |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | target, err := CanonicalizePath(target) |
| 39 | if err != nil { |
| 40 | if os.IsNotExist(err) { |
| 41 | err = nil |
| 42 | } |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | mounts, err := mountinfo.GetMounts(mountinfo.PrefixFilter(target)) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | targetSet := make(map[string]struct{}) |
| 52 | for _, m := range mounts { |
| 53 | targetSet[m.Mountpoint] = struct{}{} |
| 54 | } |
| 55 | |
| 56 | var targets []string |
| 57 | for m := range targetSet { |
| 58 | targets = append(targets, m) |
| 59 | } |
| 60 | |
| 61 | // Make the deepest mount be first |
| 62 | sort.SliceStable(targets, func(i, j int) bool { |
| 63 | return len(targets[i]) > len(targets[j]) |
| 64 | }) |
| 65 | |
| 66 | for i, target := range targets { |
| 67 | if err := UnmountAll(target, flags); err != nil { |
| 68 | if i == len(targets)-1 { // last mount |
| 69 | return err |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | func unmount(target string, flags int) error { |
| 77 | if isFUSE(target) { |
searching dependent graphs…