Skip to content

Commit

Permalink
Fix the issue meta backup is failed when symbolic links exist in meta…
Browse files Browse the repository at this point in the history
… dir. (#2255)
  • Loading branch information
KanShiori authored Aug 18, 2023
1 parent f73a527 commit 0a60bc3
Show file tree
Hide file tree
Showing 2 changed files with 20 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
14 changes: 12 additions & 2 deletions pkg/utils/ioutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,21 @@ 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, "")

link := ""
if info.Mode()&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 +126,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 0a60bc3

Please sign in to comment.