From e124e1ccbda969c073baab9b85b3d616928be975 Mon Sep 17 00:00:00 2001 From: Elara 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 } }