Always use paths relative to the container root for links

This chagne ensures that we always treat the link path as a path
relative to the container root. Without this change, relative paths
in link paths would result links being created relative to the
current working directory where the hook is executed.

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

View File

@ -108,13 +108,10 @@ func (m command) run(c *cli.Context, cfg *config) error {
}
func (m command) createLink(containerRoot string, targetPath string, link string) error {
linkPath, err := changeRoot(containerRoot, link)
if err != nil {
m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err)
}
linkPath := filepath.Join(containerRoot, link)
m.logger.Infof("Symlinking %v to %v", linkPath, targetPath)
err = os.MkdirAll(filepath.Dir(linkPath), 0755)
err := os.MkdirAll(filepath.Dir(linkPath), 0755)
if err != nil {
return fmt.Errorf("failed to create directory: %v", err)
}
@ -125,11 +122,3 @@ func (m command) createLink(containerRoot string, targetPath string, link string
return nil
}
func changeRoot(new string, path string) (string, error) {
if !filepath.IsAbs(path) {
return path, nil
}
return filepath.Join(new, path), nil
}