@@ -24,6 +24,18 @@ import (
2424 "github.com/docker/model-runner/cmd/cli/desktop"
2525)
2626
27+ // validateAbsolutePath validates that a path is absolute and returns the cleaned path
28+ func validateAbsolutePath (path , name string ) (string , error ) {
29+ if ! filepath .IsAbs (path ) {
30+ return "" , fmt .Errorf (
31+ "%s path must be absolute.\n \n " +
32+ "See 'docker model package --help' for more information" ,
33+ name ,
34+ )
35+ }
36+ return filepath .Clean (path ), nil
37+ }
38+
2739func newPackagedCmd () * cobra.Command {
2840 var opts packageOptions
2941
@@ -67,13 +79,11 @@ func newPackagedCmd() *cobra.Command {
6779
6880 // Validate GGUF path if provided
6981 if opts .ggufPath != "" {
70- if ! filepath .IsAbs (opts .ggufPath ) {
71- return fmt .Errorf (
72- "GGUF path must be absolute.\n \n " +
73- "See 'docker model package --help' for more information" ,
74- )
82+ var err error
83+ opts .ggufPath , err = validateAbsolutePath (opts .ggufPath , "GGUF" )
84+ if err != nil {
85+ return err
7586 }
76- opts .ggufPath = filepath .Clean (opts .ggufPath )
7787 }
7888
7989 // Validate safetensors directory if provided
@@ -108,24 +118,29 @@ func newPackagedCmd() *cobra.Command {
108118 }
109119
110120 for i , l := range opts .licensePaths {
111- if ! filepath .IsAbs (l ) {
112- return fmt .Errorf (
113- "license path must be absolute.\n \n " +
114- "See 'docker model package --help' for more information" ,
115- )
121+ var err error
122+ opts .licensePaths [i ], err = validateAbsolutePath (l , "license" )
123+ if err != nil {
124+ return err
125+ }
126+ }
127+
128+ // Validate chat template path if provided
129+ if opts .chatTemplatePath != "" {
130+ var err error
131+ opts .chatTemplatePath , err = validateAbsolutePath (opts .chatTemplatePath , "chat template" )
132+ if err != nil {
133+ return err
116134 }
117- opts .licensePaths [i ] = filepath .Clean (l )
118135 }
119136
120137 // Validate mmproj path if provided
121138 if opts .mmprojPath != "" {
122- if ! filepath .IsAbs (opts .mmprojPath ) {
123- return fmt .Errorf (
124- "mmproj path must be absolute.\n \n " +
125- "See 'docker model package --help' for more information" ,
126- )
139+ var err error
140+ opts .mmprojPath , err = validateAbsolutePath (opts .mmprojPath , "mmproj" )
141+ if err != nil {
142+ return err
127143 }
128- opts .mmprojPath = filepath .Clean (opts .mmprojPath )
129144 }
130145
131146 // Validate dir-tar paths are relative (not absolute)
0 commit comments