@@ -101,6 +101,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
101101 testFileOpCopyAlwaysReplaceExistingDestPaths ,
102102 testFileOpRmWildcard ,
103103 testFileOpCopyUIDCache ,
104+ testFileOpCopyChmodText ,
104105 testCallDiskUsage ,
105106 testBuildMultiMount ,
106107 testBuildHTTPSource ,
@@ -1705,6 +1706,48 @@ func testFileOpCopyRm(t *testing.T, sb integration.Sandbox) {
17051706 require .Equal (t , []byte ("file2" ), dt )
17061707}
17071708
1709+ func testFileOpCopyChmodText (t * testing.T , sb integration.Sandbox ) {
1710+ requiresLinux (t )
1711+ c , err := New (sb .Context (), sb .Address ())
1712+ require .NoError (t , err )
1713+ defer c .Close ()
1714+
1715+ tcases := []struct {
1716+ src string
1717+ dest string
1718+ mode string
1719+ }{
1720+ {"file" , "f1" , "go-w" },
1721+ {"file" , "f2" , "o-rwx,g+x" },
1722+ {"file" , "f3" , "u=rwx,g=,o=" },
1723+ {"file" , "f4" , "u+rw,g+r,o-x,o+w" },
1724+ {"dir" , "d1" , "a+X" },
1725+ {"dir" , "d2" , "g+rw,o+rw" },
1726+ }
1727+
1728+ st := llb .Image ("alpine" ).
1729+ Run (llb .Shlex (`sh -c "mkdir /input && touch /input/file && mkdir /input/dir && chmod 0400 /input/dir && mkdir /expected"` ))
1730+
1731+ for _ , tc := range tcases {
1732+ st = st .Run (llb .Shlex (`sh -c "cp -a /input/` + tc .src + ` /expected/` + tc .dest + ` && chmod ` + tc .mode + ` /expected/` + tc .dest + `"` ))
1733+ }
1734+ cp := llb .Scratch ()
1735+
1736+ for _ , tc := range tcases {
1737+ cp = cp .File (llb .Copy (st .Root (), "/input/" + tc .src , "/" + tc .dest , llb.ChmodOpt {ModeStr : tc .mode }))
1738+ }
1739+
1740+ for _ , tc := range tcases {
1741+ st = st .Run (llb .Shlex (`sh -c '[ "$(stat -c '%A' /expected/` + tc .dest + `)" == "$(stat -c '%A' /actual/` + tc .dest + `)" ]'` ), llb .AddMount ("/actual" , cp , llb .Readonly ))
1742+ }
1743+
1744+ def , err := st .Marshal (sb .Context ())
1745+ require .NoError (t , err )
1746+
1747+ _ , err = c .Solve (sb .Context (), def , SolveOpt {}, nil )
1748+ require .NoError (t , err )
1749+ }
1750+
17081751// moby/buildkit#3291
17091752func testFileOpCopyUIDCache (t * testing.T , sb integration.Sandbox ) {
17101753 requiresLinux (t )
0 commit comments