Skip to content

Commit 6e35a7a

Browse files
Billy Owirebillywr
authored andcommitted
Fix WCOW COPY --from failure in multistage builds on Windows
Fixes: moby#5193 Signed-off-by: Billy Owire <[email protected]>
1 parent 1da789b commit 6e35a7a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

cache/contenthash/checksum.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
10341034
scanPath = resolvedPath
10351035
}
10361036

1037-
err = filepath.Walk(scanPath, func(itemPath string, fi os.FileInfo, err error) error {
1037+
walkFunc := func(itemPath string, fi os.FileInfo, err error) error {
10381038
if scanCounterEnable {
10391039
scanCounter.Add(1)
10401040
}
@@ -1073,7 +1073,10 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
10731073
txn.Insert(k, cr)
10741074
}
10751075
return nil
1076-
})
1076+
}
1077+
1078+
err = cc.walk(scanPath, walkFunc)
1079+
10771080
if err != nil {
10781081
return err
10791082
}

cache/contenthash/checksum_unix.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package contenthash
5+
6+
import "path/filepath"
7+
8+
func (cc *cacheContext) walk(scanPath string, walkFunc filepath.WalkFunc) error {
9+
return filepath.Walk(scanPath, walkFunc)
10+
}

cache/contenthash/checksum_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package contenthash
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/Microsoft/go-winio"
7+
)
8+
9+
func (cc *cacheContext) walk(scanPath string, walkFunc filepath.WalkFunc) error {
10+
// elevating the admin privileges to walk special files/directory
11+
// like `System Volume Information`, etc. See similar in #4994
12+
privileges := []string{winio.SeBackupPrivilege}
13+
return winio.RunWithPrivileges(privileges, func() error {
14+
return filepath.Walk(scanPath, walkFunc)
15+
})
16+
}

0 commit comments

Comments
 (0)