Skip to content

Commit

Permalink
fix: remove link directory before linking
Browse files Browse the repository at this point in the history
  • Loading branch information
aooohan committed May 18, 2024
1 parent 6319cfc commit 725a3c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
8 changes: 2 additions & 6 deletions internal/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ func (l *LocationPackage) Link() (*Package, error) {
sourcePackage := l.from
targetPackage := l.ConvertLocation()
// If the mock path already exists, delete it first.
if util.FileExists(mockPath) {
logger.Debugf("Removing old package path: %s\n", mockPath)
if err := os.RemoveAll(mockPath); err != nil {
return nil, err
}
}
logger.Debugf("Removing old package path: %s\n", mockPath)
_ = os.RemoveAll(mockPath)
hasAddition := len(targetPackage.Additions) != 0
if !hasAddition {
logger.Debugf("Create symlink %s -> %s\n", sourcePackage.Main.Path, targetPackage.Main.Path)
Expand Down
25 changes: 3 additions & 22 deletions internal/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,11 @@ import (
)

func FileExists(filename string) bool {
fileInfo, err := os.Lstat(filename)
if err != nil {
if os.IsNotExist(err) {
return false
}
_, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}

if fileInfo.Mode()&os.ModeSymlink != 0 {
target, err := os.Readlink(filename)
if err != nil {
return false
}
_, err = os.Stat(target)
if err != nil {
if os.IsNotExist(err) {
return false
}
return false
}
return true
}

return true
return err == nil
}

func CopyFile(src, dst string) error {
Expand Down

0 comments on commit 725a3c3

Please sign in to comment.