mirror of
https://github.com/moby/buildkit.git
synced 2026-08-03 22:30:26 +00:00
Merge pull request #4603 from tonistiigi/0131-fix-stubs-cleaner
executor: recheck mount stub path within root after container run
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/continuity/fs"
|
||||
@@ -43,7 +44,7 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
|
||||
}
|
||||
|
||||
realPathNext := filepath.Dir(realPath)
|
||||
if realPath == realPathNext {
|
||||
if realPath == realPathNext || realPathNext == dir {
|
||||
break
|
||||
}
|
||||
realPath = realPathNext
|
||||
@@ -52,6 +53,11 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
|
||||
|
||||
return func() {
|
||||
for _, p := range paths {
|
||||
p, err := fs.RootPath(dir, strings.TrimPrefix(p, dir))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
st, err := os.Lstat(p)
|
||||
if err != nil {
|
||||
continue
|
||||
@@ -70,8 +76,12 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
|
||||
|
||||
// Back up the timestamps of the dir for reproducible builds
|
||||
// https://github.com/moby/buildkit/issues/3148
|
||||
dir := filepath.Dir(p)
|
||||
dirSt, err := os.Stat(dir)
|
||||
parent := filepath.Dir(p)
|
||||
if realPath, err := fs.RootPath(dir, strings.TrimPrefix(parent, dir)); err != nil || realPath != parent {
|
||||
continue
|
||||
}
|
||||
|
||||
dirSt, err := os.Stat(parent)
|
||||
if err != nil {
|
||||
bklog.G(ctx).WithError(err).Warnf("Failed to stat %q (parent of mount stub %q)", dir, p)
|
||||
continue
|
||||
@@ -88,7 +98,7 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
|
||||
}
|
||||
|
||||
// Restore the timestamps of the dir
|
||||
if err := os.Chtimes(dir, atime, mtime); err != nil {
|
||||
if err := os.Chtimes(parent, atime, mtime); err != nil {
|
||||
bklog.G(ctx).WithError(err).Warnf("Failed to restore time time mount stub timestamp (os.Chtimes(%q, %v, %v))", dir, atime, mtime)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user