Skip to content

Commit

Permalink
better relative path management
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Feb 19, 2024
1 parent 1745ba9 commit 1554233
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/slicer/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/fs"
"path/filepath"
"strings"

"github.com/canonical/chisel/internal/fsutil"
"github.com/canonical/chisel/internal/setup"
Expand Down Expand Up @@ -37,11 +38,10 @@ func NewReport(root string) *Report {
}

func (r *Report) Add(slice *setup.Slice, info *fsutil.Info) error {
relPath, err := filepath.Rel(r.Root, info.Path)
if err != nil {
return fmt.Errorf("internal error: cannot add path %q outside of root %q", info.Path, r.Root)
if !strings.HasPrefix(info.Path, r.Root) {
return fmt.Errorf("internal error: cannot add path %q outside out root %q", info.Path, r.Root)
}
relPath = "/" + relPath
relPath := filepath.Clean("/" + strings.TrimPrefix(info.Path, r.Root))

if entry, ok := r.Entries[relPath]; ok {
if info.Mode != entry.Mode || info.Link != entry.Link ||
Expand Down

0 comments on commit 1554233

Please sign in to comment.