mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
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:
parent
bfea673d6a
commit
d0d85a8c5c
@ -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 {
|
func (m command) createLink(containerRoot string, targetPath string, link string) error {
|
||||||
linkPath, err := changeRoot(containerRoot, link)
|
linkPath := filepath.Join(containerRoot, link)
|
||||||
if err != nil {
|
|
||||||
m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
m.logger.Infof("Symlinking %v to %v", linkPath, targetPath)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %v", err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func changeRoot(new string, path string) (string, error) {
|
|
||||||
if !filepath.IsAbs(path) {
|
|
||||||
return path, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return filepath.Join(new, path), nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user