Skip to content

Commit

Permalink
bugfix: following 576ada7
Browse files Browse the repository at this point in the history
  • Loading branch information
aooohan committed Feb 5, 2024
1 parent 308c409 commit 0f236a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (b *Sdk) Install(version Version) error {

func (b *Sdk) moveLocalFile(info *Info, targetPath string) error {
pterm.Printf("Moving %s to %s...\n", info.Path, targetPath)
if err := os.Rename(info.Path, targetPath); err != nil {
if err := util.MoveFiles(info.Path, targetPath); err != nil {
return fmt.Errorf("failed to move file, err:%w", err)
}
return nil
Expand Down Expand Up @@ -140,7 +140,7 @@ func (b *Sdk) moveRemoteFile(info *Info, targetPath string) error {
if decompressor == nil {
// If it is not a compressed file, move file to the corresponding sdk directory,
// and the rest be handled by the PostInstall function.
if err = os.Rename(filePath, targetPath); err != nil {
if err = util.MoveFiles(filePath, targetPath); err != nil {
return fmt.Errorf("failed to move file, err:%w", err)
}
return nil
Expand Down
31 changes: 31 additions & 0 deletions internal/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package util
import (
"io"
"os"
"path/filepath"
)

func FileExists(filename string) bool {
Expand Down Expand Up @@ -52,3 +53,33 @@ func CopyFile(src, dst string) error {

return nil
}

// MoveFiles Move a folder or file to a specified directory
func MoveFiles(src, targetDir string) error {
info, err := os.Stat(src)
if err != nil {
return err
}
if info.IsDir() {
files, err := os.ReadDir(src)
if err != nil {
return err
}

for _, file := range files {
oldPath := filepath.Join(src, file.Name())
newPath := filepath.Join(targetDir, file.Name())
err = os.Rename(oldPath, newPath)
if err != nil {
return err
}
}
} else {
newPath := filepath.Join(targetDir, filepath.Base(src))
err = os.Rename(src, newPath)
if err != nil {
return err
}
}
return nil
}

0 comments on commit 0f236a4

Please sign in to comment.