Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KanShiori committed Aug 18, 2023
1 parent f73a527 commit aa507f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/cluster/manager/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -204,7 +205,13 @@ func overwritePatch(specManager *spec.SpecManager, name, comp, packagePath strin
if utils.IsSymExist(symlink) {
os.Remove(symlink)
}
return os.Symlink(tg, symlink)

tgRelPath, err := filepath.Rel(filepath.Dir(symlink), tg)
if err != nil {
return err
}

return os.Symlink(tgRelPath, symlink)
}

func instancesToPatch(topo spec.Topology, options operator.Options) ([]spec.Instance, error) {
Expand Down
16 changes: 14 additions & 2 deletions pkg/utils/ioutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,23 @@ func Tar(writer io.Writer, from string) error {
tarW := tar.NewWriter(compressW)
defer tarW.Close()

// NOTE: filepath.Walk does not follow the symbolic link.
return filepath.Walk(from, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
header, _ := tar.FileInfoHeader(info, "")

fm := info.Mode()

link := ""
if fm&fs.ModeSymlink != 0 {
link, err = os.Readlink(path)
if err != nil {
return err
}
}

header, _ := tar.FileInfoHeader(info, link)
header.Name, _ = filepath.Rel(from, path)
// skip "."
if header.Name == "." {
Expand All @@ -116,7 +128,7 @@ func Tar(writer io.Writer, from string) error {
if err != nil {
return err
}
if !info.IsDir() {
if info.Mode().IsRegular() {
fd, err := os.Open(path)
if err != nil {
return err
Expand Down

0 comments on commit aa507f8

Please sign in to comment.