Skip to content

Commit

Permalink
Fix WCOW COPY --from failure in multistage builds on Windows
Browse files Browse the repository at this point in the history
Fixes: moby#5193

Signed-off-by: Billy Owire <[email protected]>
  • Loading branch information
Billy Owire committed Sep 4, 2024
1 parent 94d3dae commit 049f390
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cache/contenthash/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ func (cc *cacheContext) scanChecksum(ctx context.Context, m *mount, p string, fo
return nil, err
}
if scan {
if err := cc.scanPath(ctx, m, p, followTrailing); err != nil {
if err := cc.scanPathWrapper(ctx, m, p, followTrailing); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -996,13 +996,6 @@ func (cc *cacheContext) needsScan(root *iradix.Node[*CacheRecord], path string,
return cr == nil && !hasParentInTree, nil
}

// Only used by TestNeedScanChecksumRegression to make sure scanPath is not
// called for paths we have already scanned.
var (
scanCounterEnable bool
scanCounter atomic.Uint64
)

func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, followTrailing bool) (retErr error) {
p = path.Join("/", p)

Expand Down Expand Up @@ -1074,6 +1067,7 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
}
return nil
})

if err != nil {
return err
}
Expand All @@ -1082,6 +1076,13 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
return nil
}

// Only used by TestNeedScanChecksumRegression to make sure scanPath is not
// called for paths we have already scanned.
var (
scanCounterEnable bool
scanCounter atomic.Uint64
)

// followLinksCallback is called after we try to resolve each element. If the
// path was not found, cr is nil.
type followLinksCallback func(path string, cr *CacheRecord) error
Expand Down
8 changes: 8 additions & 0 deletions cache/contenthash/checksum_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !windows
// +build !windows

package contenthash

func (cc *cacheContext) scanPathWrapper(ctx context.Context, m *mount, p string, trailing bool) error {
return cc.scanPath(ctx, m, p, trailing)
}
13 changes: 13 additions & 0 deletions cache/contenthash/checksum_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package contenthash

import (
"context"
"github.com/Microsoft/go-winio"
)

func (cc *cacheContext) scanPathWrapper(ctx context.Context, m *mount, p string, trailing bool) error {
privileges := []string{winio.SeBackupPrivilege}
return winio.RunWithPrivileges(privileges, func() error {
return cc.scanPath(ctx, m, p, trailing)
})
}

0 comments on commit 049f390

Please sign in to comment.