Skip to content

Commit

Permalink
executor: recheck mount stub path within root after container run
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 96ccaec09c51176a6d954fd7c4ce57d519bae1b2)
(cherry picked from commit a9523c6476f39bb44dd02bcab19e8cb25c5bc37b)
  • Loading branch information
tonistiigi committed Jan 31, 2024
1 parent 92cc595 commit 00fe637
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions executor/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"
"syscall"

"github.com/containerd/continuity/fs"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 00fe637

Please sign in to comment.