diff --git a/cache/contenthash/checksum.go b/cache/contenthash/checksum.go index 7b592c794f8e..ece58b425508 100644 --- a/cache/contenthash/checksum.go +++ b/cache/contenthash/checksum.go @@ -1034,7 +1034,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) } @@ -1073,7 +1073,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 } diff --git a/cache/contenthash/checksum_unix.go b/cache/contenthash/checksum_unix.go new file mode 100644 index 000000000000..444518ddd814 --- /dev/null +++ b/cache/contenthash/checksum_unix.go @@ -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) +} diff --git a/cache/contenthash/checksum_windows.go b/cache/contenthash/checksum_windows.go new file mode 100644 index 000000000000..9e0c020230ed --- /dev/null +++ b/cache/contenthash/checksum_windows.go @@ -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) + }) +}