@@ -25,10 +25,7 @@ import (
2525 "github.com/urfave/cli/v2"
2626
2727 "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
28- "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
29- "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
3028 "github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
31- "github.com/NVIDIA/nvidia-container-toolkit/internal/platform-support/tegra/csv"
3229)
3330
3431type command struct {
@@ -37,7 +34,6 @@ type command struct {
3734
3835type config struct {
3936 hostRoot string
40- filenames cli.StringSlice
4137 links cli.StringSlice
4238 containerSpec string
4339}
@@ -50,39 +46,36 @@ func NewCommand(logger logger.Interface) *cli.Command {
5046 return c .build ()
5147}
5248
53- // build
49+ // build creates the create-symlink command.
5450func (m command ) build () * cli.Command {
5551 cfg := config {}
5652
57- // Create the '' command
5853 c := cli.Command {
5954 Name : "create-symlinks" ,
60- Usage : "A hook to create symlinks in the container. This can be used to process CSV mount specs " ,
55+ Usage : "A hook to create symlinks in the container." ,
6156 Action : func (c * cli.Context ) error {
6257 return m .run (c , & cfg )
6358 },
6459 }
6560
6661 c .Flags = []cli.Flag {
67- & cli.StringFlag {
68- Name : "host-root" ,
69- Usage : "The root on the host filesystem to use to resolve symlinks" ,
70- Destination : & cfg .hostRoot ,
71- },
72- & cli.StringSliceFlag {
73- Name : "csv-filename" ,
74- Usage : "Specify a (CSV) filename to process" ,
75- Destination : & cfg .filenames ,
76- },
7762 & cli.StringSliceFlag {
7863 Name : "link" ,
7964 Usage : "Specify a specific link to create. The link is specified as target::link" ,
8065 Destination : & cfg .links ,
8166 },
67+ // The following flags are testing-only flags.
68+ & cli.StringFlag {
69+ Name : "host-root" ,
70+ Usage : "The root on the host filesystem to use to resolve symlinks. This is only intended for testing." ,
71+ Destination : & cfg .hostRoot ,
72+ Hidden : true ,
73+ },
8274 & cli.StringFlag {
8375 Name : "container-spec" ,
84- Usage : "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN" ,
76+ 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. " ,
8577 Destination : & cfg .containerSpec ,
78+ Hidden : true ,
8679 },
8780 }
8881
@@ -100,53 +93,8 @@ func (m command) run(c *cli.Context, cfg *config) error {
10093 return fmt .Errorf ("failed to determined container root: %v" , err )
10194 }
10295
103- csvFiles := cfg .filenames .Value ()
104-
105- chainLocator := lookup .NewSymlinkChainLocator (
106- lookup .WithLogger (m .logger ),
107- lookup .WithRoot (cfg .hostRoot ),
108- )
109-
110- var candidates []string
111- for _ , file := range csvFiles {
112- mountSpecs , err := csv .NewCSVFileParser (m .logger , file ).Parse ()
113- if err != nil {
114- m .logger .Debugf ("Skipping CSV file %v: %v" , file , err )
115- continue
116- }
117-
118- for _ , ms := range mountSpecs {
119- if ms .Type != csv .MountSpecSym {
120- continue
121- }
122- targets , err := chainLocator .Locate (ms .Path )
123- if err != nil {
124- m .logger .Warningf ("Failed to locate symlink %v" , ms .Path )
125- }
126- candidates = append (candidates , targets ... )
127- }
128- }
129-
13096 created := make (map [string ]bool )
131- // candidates is a list of absolute paths to symlinks in a chain, or the final target of the chain.
132- for _ , candidate := range candidates {
133- target , err := symlinks .Resolve (candidate )
134- if err != nil {
135- m .logger .Debugf ("Skipping invalid link: %v" , err )
136- continue
137- } else if target == candidate {
138- m .logger .Debugf ("%v is not a symlink" , candidate )
139- continue
140- }
141-
142- err = m .createLink (created , cfg .hostRoot , containerRoot , target , candidate )
143- if err != nil {
144- m .logger .Warningf ("Failed to create link %v: %v" , []string {target , candidate }, err )
145- }
146- }
147-
148- links := cfg .links .Value ()
149- for _ , l := range links {
97+ for _ , l := range cfg .links .Value () {
15098 parts := strings .Split (l , "::" )
15199 if len (parts ) != 2 {
152100 m .logger .Warningf ("Invalid link specification %v" , l )
@@ -158,9 +106,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
158106 m .logger .Warningf ("Failed to create link %v: %v" , parts , err )
159107 }
160108 }
161-
162109 return nil
163-
164110}
165111
166112func (m command ) createLink (created map [string ]bool , hostRoot string , containerRoot string , target string , link string ) error {
@@ -207,18 +153,3 @@ func changeRoot(current string, new string, path string) (string, error) {
207153
208154 return filepath .Join (new , relative ), nil
209155}
210-
211- // Locate returns the link target of the specified filename or an empty slice if the
212- // specified filename is not a symlink.
213- func (m command ) Locate (filename string ) ([]string , error ) {
214- target , err := symlinks .Resolve (filename )
215- if err != nil {
216- return nil , err
217- }
218- if target == filename {
219- m .logger .Debugf ("%v is not a symlink" , filename )
220- return nil , nil
221- }
222- m .logger .Debugf ("Resolved link: '%v' => '%v'" , filename , target )
223- return []string {target }, nil
224- }
0 commit comments