[no-relnote] Remove unused hostRoot argument

The hostRoot argument is always empty and not applicable to
how links are specified.

Links are specified by the paths in the container filesystem and as such
the only transform required to change the root is a join of the filepath.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2024-10-22 12:11:41 +02:00 committed by Christopher Desiniotis
parent 6a6a3e6055
commit bfea673d6a
No known key found for this signature in database
GPG Key ID: 603C8E544D789A89

View File

@ -33,7 +33,6 @@ type command struct {
} }
type config struct { type config struct {
hostRoot string
links cli.StringSlice links cli.StringSlice
containerSpec string containerSpec string
} }
@ -65,12 +64,6 @@ func (m command) build() *cli.Command {
Destination: &cfg.links, Destination: &cfg.links,
}, },
// The following flags are testing-only flags. // The following flags are testing-only flags.
&cli.StringFlag{
Name: "host-root",
Usage: "The root on the host filesystem to use to resolve symlinks. This is only intended for testing.",
Destination: &cfg.hostRoot,
Hidden: true,
},
&cli.StringFlag{ &cli.StringFlag{
Name: "container-spec", Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.", Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.",
@ -105,7 +98,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
continue continue
} }
err := m.createLink(cfg.hostRoot, containerRoot, parts[0], parts[1]) err := m.createLink(containerRoot, parts[0], parts[1])
if err != nil { if err != nil {
m.logger.Warningf("Failed to create link %v: %v", parts, err) m.logger.Warningf("Failed to create link %v: %v", parts, err)
} }
@ -114,8 +107,8 @@ func (m command) run(c *cli.Context, cfg *config) error {
return nil return nil
} }
func (m command) createLink(hostRoot string, containerRoot string, targetPath string, link string) error { func (m command) createLink(containerRoot string, targetPath string, link string) error {
linkPath, err := changeRoot(hostRoot, containerRoot, link) linkPath, err := changeRoot(containerRoot, link)
if err != nil { if err != nil {
m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err) m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err)
} }
@ -133,19 +126,10 @@ func (m command) createLink(hostRoot string, containerRoot string, targetPath st
return nil return nil
} }
func changeRoot(current string, new string, path string) (string, error) { func changeRoot(new string, path string) (string, error) {
if !filepath.IsAbs(path) { if !filepath.IsAbs(path) {
return path, nil return path, nil
} }
relative := path return filepath.Join(new, path), nil
if current != "" {
r, err := filepath.Rel(current, path)
if err != nil {
return "", err
}
relative = r
}
return filepath.Join(new, relative), nil
} }