Skip to content

Commit

Permalink
refactor: make code more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana committed Dec 20, 2024
1 parent f57c9ba commit 5970ce0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions agent/command/archive_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
)

// isRel checks if the candidate path is relative to the target path.
func isRel(candidate, target string) bool {
if filepath.IsAbs(candidate) {
func isRel(filePath, rootPath string) bool {
if filepath.IsAbs(filePath) {
return false
}
realpath, err := filepath.EvalSymlinks(filepath.Join(target, candidate))
realpath, err := filepath.EvalSymlinks(filepath.Join(rootPath, filePath))
if err != nil {
return false
}
relpath, err := filepath.Rel(target, realpath)
relpath, err := filepath.Rel(rootPath, realpath)
return err == nil && !strings.HasPrefix(filepath.Clean(relpath), "..")
}

Expand Down Expand Up @@ -162,7 +162,7 @@ tarReaderLoop:
}

if !isRel(hdr.Linkname, rootPath) || !isRel(hdr.Name, rootPath) {
return errors.Wrap(err, "symlinks must be relative to the root path")
return errors.Wrap(err, "artifact paths should be relative to the root path")
}

namePath := filepath.Join(rootPath, hdr.Name)
Expand Down

0 comments on commit 5970ce0

Please sign in to comment.