From 946231167de813adf1c40e75ef082c26e473a381 Mon Sep 17 00:00:00 2001 From: Laurence <45508533+LaurenceLiZhixin@users.noreply.github.com> Date: Thu, 16 Feb 2023 19:52:30 +0800 Subject: [PATCH] Fix: make rename replace old dir (#1237) * Fix: make rename replace old dir Co-authored-by: lizhixin.lzx --- pkg/yurthub/util/fs/store.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/yurthub/util/fs/store.go b/pkg/yurthub/util/fs/store.go index e6712e05e73..bec2da6364f 100644 --- a/pkg/yurthub/util/fs/store.go +++ b/pkg/yurthub/util/fs/store.go @@ -253,6 +253,13 @@ func (fs *FileSystemOperator) Rename(oldPath string, newPath string) error { if !IfExists(oldPath) { return ErrNotExists } + + if ok, err := IsDir(newPath); ok && err == nil { + if err := fs.DeleteDir(newPath); err != nil { + return err + } + } + if filepath.Dir(oldPath) != filepath.Dir(newPath) { return ErrInvalidPath }