@@ -17,6 +17,7 @@ import (
17
17
"golang.org/x/net/context"
18
18
19
19
"github.com/docker/docker/api"
20
+ "github.com/docker/docker/builder"
20
21
"github.com/docker/docker/builder/dockerignore"
21
22
Cli "github.com/docker/docker/cli"
22
23
"github.com/docker/docker/opts"
@@ -143,7 +144,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
143
144
}
144
145
}
145
146
146
- if err := validateContextDirectory (contextDir , excludes ); err != nil {
147
+ if err := builder . ValidateContextDirectory (contextDir , excludes ); err != nil {
147
148
return fmt .Errorf ("Error checking context: '%s'." , err )
148
149
}
149
150
@@ -281,54 +282,6 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
281
282
return nil
282
283
}
283
284
284
- // validateContextDirectory checks if all the contents of the directory
285
- // can be read and returns an error if some files can't be read
286
- // symlinks which point to non-existing files don't trigger an error
287
- func validateContextDirectory (srcPath string , excludes []string ) error {
288
- contextRoot , err := getContextRoot (srcPath )
289
- if err != nil {
290
- return err
291
- }
292
- return filepath .Walk (contextRoot , func (filePath string , f os.FileInfo , err error ) error {
293
- // skip this directory/file if it's not in the path, it won't get added to the context
294
- if relFilePath , err := filepath .Rel (contextRoot , filePath ); err != nil {
295
- return err
296
- } else if skip , err := fileutils .Matches (relFilePath , excludes ); err != nil {
297
- return err
298
- } else if skip {
299
- if f .IsDir () {
300
- return filepath .SkipDir
301
- }
302
- return nil
303
- }
304
-
305
- if err != nil {
306
- if os .IsPermission (err ) {
307
- return fmt .Errorf ("can't stat '%s'" , filePath )
308
- }
309
- if os .IsNotExist (err ) {
310
- return nil
311
- }
312
- return err
313
- }
314
-
315
- // skip checking if symlinks point to non-existing files, such symlinks can be useful
316
- // also skip named pipes, because they hanging on open
317
- if f .Mode ()& (os .ModeSymlink | os .ModeNamedPipe ) != 0 {
318
- return nil
319
- }
320
-
321
- if ! f .IsDir () {
322
- currentFile , err := os .Open (filePath )
323
- if err != nil && os .IsPermission (err ) {
324
- return fmt .Errorf ("no permission to read from '%s'" , filePath )
325
- }
326
- currentFile .Close ()
327
- }
328
- return nil
329
- })
330
- }
331
-
332
285
// validateTag checks if the given image name can be resolved.
333
286
func validateTag (rawRepo string ) (string , error ) {
334
287
_ , err := reference .ParseNamed (rawRepo )
0 commit comments