From bb017b471ebec09d2f020c3cb144c3a028b60f34 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Mon, 17 Oct 2022 12:19:23 -0700 Subject: [PATCH] Stop DBus errors from causing panics by checking error type (Arsen6331/itd#29) --- blefs/all.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/blefs/all.go b/blefs/all.go index 7ba9809..5978de2 100644 --- a/blefs/all.go +++ b/blefs/all.go @@ -23,7 +23,13 @@ func (blefs *FS) RemoveAll(path string) error { return blefs.removeAllChildren(path) } else { err = blefs.Remove(path) - if err != nil && err.(FSError).Code != -2 { + + var code int8 + if err, ok := err.(FSError); ok { + code = err.Code + } + + if err != nil && code != -2 { return err } } @@ -50,7 +56,13 @@ func (blefs *FS) removeAllChildren(path string) error { } else { err = blefs.Remove(entryPath) } - if err != nil && err.(FSError).Code != -2 { + + var code int8 + if err, ok := err.(FSError); ok { + code = err.Code + } + + if err != nil && code != -2 { return err } } @@ -68,7 +80,13 @@ func (blefs *FS) MkdirAll(path string) error { curPath := strings.Join(splitPath[0:i+1], "/") err := blefs.Mkdir(curPath) - if err != nil && err.(FSError).Code != -17 { + + var code int8 + if err, ok := err.(FSError); ok { + code = err.Code + } + + if err != nil && code != -17 { return err } }