Skip to content

Commit

Permalink
[Backport release-v1.2] Fix: make rename replace old dir (#1241)
Browse files Browse the repository at this point in the history
* Fix: make rename replace old dir

(cherry picked from commit 773cecb)

* Fix: check is dir in FileSystemOperator.rename function

(cherry picked from commit de8c339)

---------

Co-authored-by: lizhixin.lzx <[email protected]>
  • Loading branch information
github-actions[bot] and lizhixin.lzx authored Feb 17, 2023
1 parent 4e4eb51 commit 8b41abc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/yurthub/util/fs/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8b41abc

Please sign in to comment.