@@ -46,6 +46,7 @@ import (
4646 digest "github.com/opencontainers/go-digest"
4747 ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
4848 "github.com/pkg/errors"
49+ mode "github.com/tonistiigi/dchapes-mode"
4950 "golang.org/x/sync/errgroup"
5051)
5152
@@ -1390,19 +1391,26 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
13901391 copyOpt = append (copyOpt , llb .WithExcludePatterns (cfg .excludePatterns ))
13911392 }
13921393
1393- var mode * llb.ChmodOpt
1394+ var chopt * llb.ChmodOpt
13941395 if cfg .chmod != "" {
1395- mode = & llb.ChmodOpt {}
1396+ chopt = & llb.ChmodOpt {}
13961397 p , err := strconv .ParseUint (cfg .chmod , 8 , 32 )
13971398 nonOctalErr := errors .Errorf ("invalid chmod parameter: '%v'. it should be octal string and between 0 and 07777" , cfg .chmod )
13981399 if err == nil {
13991400 if p > 0o7777 {
14001401 return nonOctalErr
14011402 }
1402- mode .Mode = os .FileMode (p )
1403+ chopt .Mode = os .FileMode (p )
14031404 } else {
14041405 if featureCopyChmodNonOctalEnabled {
1405- mode .ModeStr = cfg .chmod
1406+ if _ , err := mode .Parse (cfg .chmod ); err != nil {
1407+ var ne * strconv.NumError
1408+ if errors .As (err , & ne ) {
1409+ return nonOctalErr // return nonOctalErr for compatibility if the value looks numeric
1410+ }
1411+ return err
1412+ }
1413+ chopt .ModeStr = cfg .chmod
14061414 } else {
14071415 return nonOctalErr
14081416 }
@@ -1467,7 +1475,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
14671475 }
14681476 st := llb .Git (gitRef .Remote , commit , gitOptions ... )
14691477 opts := append ([]llb.CopyOption {& llb.CopyInfo {
1470- Mode : mode ,
1478+ Mode : chopt ,
14711479 CreateDestPath : true ,
14721480 }}, copyOpt ... )
14731481 if a == nil {
@@ -1496,7 +1504,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
14961504 st := llb .HTTP (src , llb .Filename (f ), llb .WithCustomName (pgName ), llb .Checksum (cfg .checksum ), dfCmd (cfg .params ))
14971505
14981506 opts := append ([]llb.CopyOption {& llb.CopyInfo {
1499- Mode : mode ,
1507+ Mode : chopt ,
15001508 CreateDestPath : true ,
15011509 }}, copyOpt ... )
15021510
@@ -1532,7 +1540,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
15321540 }
15331541
15341542 opts := append ([]llb.CopyOption {& llb.CopyInfo {
1535- Mode : mode ,
1543+ Mode : chopt ,
15361544 FollowSymlinks : true ,
15371545 CopyDirContentsOnly : true ,
15381546 IncludePatterns : patterns ,
@@ -1565,7 +1573,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
15651573 )
15661574
15671575 opts := append ([]llb.CopyOption {& llb.CopyInfo {
1568- Mode : mode ,
1576+ Mode : chopt ,
15691577 CreateDestPath : true ,
15701578 }}, copyOpt ... )
15711579
0 commit comments