From 904184398134a1af17c316c92d335e03aa0de341 Mon Sep 17 00:00:00 2001 From: mkvolkov Date: Sat, 20 Aug 2022 13:21:54 +0300 Subject: [PATCH] RemoveAll finished --- rclonefs/fs.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/rclonefs/fs.go b/rclonefs/fs.go index 3616d93..55074a2 100644 --- a/rclonefs/fs.go +++ b/rclonefs/fs.go @@ -108,6 +108,7 @@ func (rcfs *RCFS) Remove(name string) error { func (rcfs *RCFS) RemoveAll(path string) error { path = rcfs.AbsPath(path) + afero.Walk(rcfs, path, func(path string, info fs.FileInfo, err error) error { if err != nil { return err @@ -121,6 +122,30 @@ func (rcfs *RCFS) RemoveAll(path string) error { } }) + for { + if ok, err := afero.IsEmpty(rcfs, path); err == nil { + if ok { + rcfs.Remove(path) + break + } + } else { + return err + } + + afero.Walk(rcfs, path, func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + + if ok, err := afero.IsEmpty(rcfs, path); ok { + rcfs.Remove(path) + return nil + } else { + return err + } + }) + } + return nil }