From 53d45135f0fc743310a9cf83e9d942d7af61b52b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 2 Oct 2020 09:27:58 +0200 Subject: [PATCH 1/2] mount.RecursiveUnmount() calculate "last mount" outside loop Signed-off-by: Sebastiaan van Stijn --- mount/mount_unix.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mount/mount_unix.go b/mount/mount_unix.go index b47ab875..9279acee 100644 --- a/mount/mount_unix.go +++ b/mount/mount_unix.go @@ -61,11 +61,14 @@ func RecursiveUnmount(target string) error { return len(mounts[i].Mountpoint) > len(mounts[j].Mountpoint) }) - var suberr error + var ( + suberr error + lastMount = len(mounts) - 1 + ) for i, m := range mounts { err = Unmount(m.Mountpoint) if err != nil { - if i == len(mounts)-1 { // last mount + if i == lastMount { return fmt.Errorf("%w (possible cause: %s)", err, suberr) } // This is a submount, we can ignore the error for now, From 9ffc9f43040ce35fff56150d1b8f94afc77fed13 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 2 Oct 2020 09:30:01 +0200 Subject: [PATCH 2/2] mount.RecursiveUnmount(): omit empty "sub-errors" in error message Signed-off-by: Sebastiaan van Stijn --- mount/mount_unix.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mount/mount_unix.go b/mount/mount_unix.go index 9279acee..a250bfc8 100644 --- a/mount/mount_unix.go +++ b/mount/mount_unix.go @@ -69,7 +69,10 @@ func RecursiveUnmount(target string) error { err = Unmount(m.Mountpoint) if err != nil { if i == lastMount { - return fmt.Errorf("%w (possible cause: %s)", err, suberr) + if suberr != nil { + return fmt.Errorf("%w (possible cause: %s)", err, suberr) + } + return err } // This is a submount, we can ignore the error for now, // the final unmount will fail if this is a real problem.