From b476853dc0e3fc641a9fd104fe3847e4ebc09f92 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sun, 16 Oct 2022 12:39:11 -0700 Subject: [PATCH] Fix RemoveAll() and MkdirAll() functions --- blefs/all.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/blefs/all.go b/blefs/all.go index 56d82c4..7ba9809 100644 --- a/blefs/all.go +++ b/blefs/all.go @@ -38,12 +38,19 @@ func (blefs *FS) removeAllChildren(path string) error { } for _, entry := range list { + name := entry.Name() + + if name == "." || name == ".." { + continue + } + entryPath := filepath.Join(path, name) + if entry.IsDir() { - err = blefs.removeAllChildren(filepath.Join(path, entry.Name())) + err = blefs.removeAllChildren(entryPath) } else { - err = blefs.Remove(path) + err = blefs.Remove(entryPath) } - if err != nil { + if err != nil && err.(FSError).Code != -2 { return err } } @@ -58,7 +65,7 @@ func (blefs *FS) MkdirAll(path string) error { splitPath := strings.Split(path, "/") for i := 1; i < len(splitPath); i++ { - curPath := strings.Join(splitPath[0:i], "/") + curPath := strings.Join(splitPath[0:i+1], "/") err := blefs.Mkdir(curPath) if err != nil && err.(FSError).Code != -17 {