Skip to content

Ensure that extra symlinks don't overlap with RPM included symlinks #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cmd/rpm2tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"archive/tar"
"fmt"
"os"
"path/filepath"
"sort"
"strings"

"github.com/spf13/cobra"

"github.com/rmohr/bazeldnf/pkg/order"
"github.com/rmohr/bazeldnf/pkg/rpm"
"github.com/spf13/cobra"
)

type rpm2tarOpts struct {
Expand Down Expand Up @@ -55,12 +57,12 @@ func NewRpm2TarCmd() *cobra.Command {
}
for _, k := range rpm2taropts.sortedSymlinks {
v := rpm2taropts.symlinks[k]
// If an absolute path is given let's add a `.` in front. This is
// not strictly necessary but adds a more correct tar path
// which aligns with the usual rpm entries which start with `./`
if strings.HasPrefix(k, "/") {
k = "." + k
// prefix link paths with `./` which aligns with the usual rpm entries which start with `./`.
if !strings.HasPrefix(k, "./") {
k = "./" + strings.TrimPrefix(filepath.Clean(k), "/")
}
// Add normalized symlink to created paths to avoid recreation when merging RPMs
collector.AddPath(k)
directoryTree.Add(
[]tar.Header{
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/rpm/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func NewCollector() *Collector {
}
}

func (c *Collector) AddPath(path string) {
c.createdPaths[path] = struct{}{}
}

func (c *Collector) RPMToTar(rpmReader io.Reader, tarWriter *tar.Writer, noSymlinksAndDirs bool, capabilities map[string][]string, selinuxLabels map[string]string) error {
rpm, err := rpmutils.ReadRpm(rpmReader)
if err != nil {
Expand Down
Loading