mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Add RelativeToRoot function to Driver
This adds a function to return a path as a path relative to the specified driver root. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
aae3da88c3
commit
55ea268829
@ -19,6 +19,7 @@ package root
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||
@ -47,6 +48,18 @@ func New(opts ...Option) *Driver {
|
||||
return d
|
||||
}
|
||||
|
||||
// RelativeToRoot returns the specified path relative to the driver root.
|
||||
func (r *Driver) RelativeToRoot(path string) string {
|
||||
if r.Root == "" || r.Root == "/" {
|
||||
return path
|
||||
}
|
||||
if !filepath.IsAbs(path) {
|
||||
return path
|
||||
}
|
||||
|
||||
return strings.TrimPrefix(path, r.Root)
|
||||
}
|
||||
|
||||
// Files returns a Locator for arbitrary driver files.
|
||||
func (r *Driver) Files(opts ...lookup.Option) lookup.Locator {
|
||||
return lookup.NewFileLocator(
|
||||
|
Loading…
Reference in New Issue
Block a user