Skip to content

Commit

Permalink
mount/RecursiveUnmount: rm logrus, save error
Browse files Browse the repository at this point in the history
Since I use fmt.Error("%w") which requires go 1.13, let's
fail to build on an older golang version.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Mar 13, 2020
1 parent 173ef0d commit 487129d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions mount/mount.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// +build go1.13

package mount

import (
"fmt"
"sort"
"strconv"

"github.com/sirupsen/logrus"
)

// mountError records an error from mount or unmount operation
Expand Down Expand Up @@ -95,18 +96,21 @@ func RecursiveUnmount(target string) error {
return len(mounts[i].Mountpoint) > len(mounts[j].Mountpoint)
})

var suberr error
for i, m := range mounts {
logrus.Debugf("Trying to unmount %s", m.Mountpoint)
err = unmount(m.Mountpoint, mntDetach)
if err != nil {
if i == len(mounts)-1 { // last mount
return err
return fmt.Errorf("%w (possible cause: %s)", err, suberr)
}
// This is a submount, we can ignore the error for now,
// the final unmount will fail if this is a real problem.
// With that in mind, the _first_ failed unmount error
// might be the real error cause, so let's keep it.
if suberr == nil {
suberr = err
}
// This is some submount, we can ignore this error for now, the final unmount will fail if this is a real problem
logrus.WithError(err).Warnf("Failed to unmount submount %s", m.Mountpoint)
}

logrus.Debugf("Unmounted %s", m.Mountpoint)
}
return nil
}

0 comments on commit 487129d

Please sign in to comment.