Skip to content

Commit b5c7fde

Browse files
authored
Merge pull request #137 from rmohr/xattrs1
Make xattr more flexible on different tar formats
2 parents e72ea52 + 9343dda commit b5c7fde

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

cmd/xattr.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package main
33
import (
44
"archive/tar"
55
"os"
6+
"path/filepath"
67
"strings"
78

8-
"github.com/rmohr/bazeldnf/pkg/xattr"
99
"github.com/spf13/cobra"
10+
11+
"github.com/rmohr/bazeldnf/pkg/xattr"
1012
)
1113

1214
type xattrOpts struct {
@@ -29,12 +31,12 @@ func NewXATTRCmd() *cobra.Command {
2931
for file, caps := range xattropts.capabilities {
3032
split := strings.Split(caps, ":")
3133
if len(split) > 0 {
32-
capabilityMap["./"+strings.TrimPrefix(file, "/")] = split
34+
capabilityMap[filepath.Clean(strings.TrimPrefix(file, "/"))] = split
3335
}
3436
}
3537
labelMap := map[string]string{}
3638
for file, label := range xattropts.selinuxLabels {
37-
labelMap["./"+strings.TrimPrefix(file, "/")] = label
39+
labelMap[filepath.Clean(strings.TrimPrefix(file, "/"))] = label
3840
}
3941

4042
streamInput := os.Stdin

pkg/xattr/xattr.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"archive/tar"
55
"fmt"
66
"io"
7+
"path/filepath"
8+
"strings"
79
)
810

911
const (
@@ -71,13 +73,14 @@ func enrichEntry(entry *tar.Header, capabilties map[string][]string, labels map[
7173
if entry.PAXRecords == nil {
7274
entry.PAXRecords = map[string]string{}
7375
}
76+
fileName := filepath.Clean(strings.TrimPrefix(entry.Name, "/"))
7477

75-
if caps, exists := capabilties[entry.Name]; exists {
78+
if caps, exists := capabilties[fileName]; exists {
7679
if err := AddCapabilities(entry.PAXRecords, caps); err != nil {
7780
return err
7881
}
7982
}
80-
if l, exists := labels[entry.Name]; exists {
83+
if l, exists := labels[fileName]; exists {
8184
if err := SetSELinuxLabel(entry.PAXRecords, l); err != nil {
8285
return err
8386
}

0 commit comments

Comments
 (0)