Skip to content

Commit

Permalink
Merge pull request moby#5289 from billywr/wcow-copy-from-multistage-b…
Browse files Browse the repository at this point in the history
…uilds-failure

fix(WCOW): fix file access failure for multistage builds
  • Loading branch information
gabriel-samfira authored Oct 7, 2024
2 parents 293ef59 + 6e35a7a commit c1dacbc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cache/contenthash/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
scanPath = resolvedPath
}

err = filepath.Walk(scanPath, func(itemPath string, fi os.FileInfo, err error) error {
walkFunc := func(itemPath string, fi os.FileInfo, err error) error {
if scanCounterEnable {
scanCounter.Add(1)
}
Expand Down Expand Up @@ -1082,7 +1082,10 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
txn.Insert(k, cr)
}
return nil
})
}

err = cc.walk(scanPath, walkFunc)

if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions cache/contenthash/checksum_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows
// +build !windows

package contenthash

import "path/filepath"

func (cc *cacheContext) walk(scanPath string, walkFunc filepath.WalkFunc) error {
return filepath.Walk(scanPath, walkFunc)
}
16 changes: 16 additions & 0 deletions cache/contenthash/checksum_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package contenthash

import (
"path/filepath"

"github.com/Microsoft/go-winio"
)

func (cc *cacheContext) walk(scanPath string, walkFunc filepath.WalkFunc) error {
// elevating the admin privileges to walk special files/directory
// like `System Volume Information`, etc. See similar in #4994
privileges := []string{winio.SeBackupPrivilege}
return winio.RunWithPrivileges(privileges, func() error {
return filepath.Walk(scanPath, walkFunc)
})
}

0 comments on commit c1dacbc

Please sign in to comment.