Skip to content

Commit

Permalink
chunked, dump: use CleanAbsPath
Browse files Browse the repository at this point in the history
replacing the usage of a private function.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Dec 11, 2024
1 parent ce01866 commit 8fa5ca4
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions pkg/chunked/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/containers/storage/pkg/chunked/internal"
storagePath "github.com/containers/storage/pkg/chunked/internal/path"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -103,18 +104,8 @@ func getStMode(mode uint32, typ string) (uint32, error) {
return mode, nil
}

func sanitizeName(name string) string {
path := filepath.Clean(name)
if path == "." {
path = "/"
} else if path[0] != '/' {
path = "/" + path
}
return path
}

func dumpNode(out io.Writer, added map[string]*internal.FileMetadata, links map[string]int, verityDigests map[string]string, entry *internal.FileMetadata) error {
path := sanitizeName(entry.Name)
path := storagePath.CleanAbsPath(entry.Name)

parent := filepath.Dir(path)
if _, found := added[parent]; !found && path != "/" {
Expand Down Expand Up @@ -172,7 +163,7 @@ func dumpNode(out io.Writer, added map[string]*internal.FileMetadata, links map[
if entry.Type == internal.TypeSymlink {
payload = entry.Linkname
} else {
payload = sanitizeName(entry.Linkname)
payload = storagePath.CleanAbsPath(entry.Linkname)
}
} else {
if len(entry.Digest) > 10 {
Expand Down

0 comments on commit 8fa5ca4

Please sign in to comment.