From f8dbc31b78eeb67709bfe0550f8a12d451136a20 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 6 Mar 2020 12:28:41 -0800 Subject: [PATCH] pkg/system.EnsureRemoveAll: don't call Mounted 1. Call to mount.Mounted() is very expensive and it's redundant to call it before Unmount(). 2. Calling mount.Mounted() after an error from Unmount() is questionable -- if umount failed, the mount is probably still there anyway, it doesn't make sense to check it. This should result in faster code with no change in functionality. Signed-off-by: Kir Kolyshkin --- pkg/system/rm.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/system/rm.go b/pkg/system/rm.go index b310991800..ef7f505fdf 100644 --- a/pkg/system/rm.go +++ b/pkg/system/rm.go @@ -63,12 +63,8 @@ func EnsureRemoveAll(dir string) error { return err } - if mounted, _ := mount.Mounted(pe.Path); mounted { - if e := mount.Unmount(pe.Path); e != nil { - if mounted, _ := mount.Mounted(pe.Path); mounted { - return errors.Wrapf(e, "error while removing %s", dir) - } - } + if e := mount.Unmount(pe.Path); e != nil { + return errors.Wrapf(e, "error while removing %s", dir) } if exitOnErr[pe.Path] == maxRetry {