Skip to content

Commit 00fe637

Browse files
committed
executor: recheck mount stub path within root after container run
Signed-off-by: Tonis Tiigi <[email protected]> (cherry picked from commit 96ccaec09c51176a6d954fd7c4ce57d519bae1b2) (cherry picked from commit a9523c6476f39bb44dd02bcab19e8cb25c5bc37b)
1 parent 92cc595 commit 00fe637

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

executor/stubs.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"os"
77
"path/filepath"
8+
"strings"
89
"syscall"
910

1011
"github.com/containerd/continuity/fs"
@@ -43,7 +44,7 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
4344
}
4445

4546
realPathNext := filepath.Dir(realPath)
46-
if realPath == realPathNext {
47+
if realPath == realPathNext || realPathNext == dir {
4748
break
4849
}
4950
realPath = realPathNext
@@ -52,6 +53,11 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
5253

5354
return func() {
5455
for _, p := range paths {
56+
p, err := fs.RootPath(dir, strings.TrimPrefix(p, dir))
57+
if err != nil {
58+
continue
59+
}
60+
5561
st, err := os.Lstat(p)
5662
if err != nil {
5763
continue
@@ -70,8 +76,12 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
7076

7177
// Back up the timestamps of the dir for reproducible builds
7278
// https://github.com/moby/buildkit/issues/3148
73-
dir := filepath.Dir(p)
74-
dirSt, err := os.Stat(dir)
79+
parent := filepath.Dir(p)
80+
if realPath, err := fs.RootPath(dir, strings.TrimPrefix(parent, dir)); err != nil || realPath != parent {
81+
continue
82+
}
83+
84+
dirSt, err := os.Stat(parent)
7585
if err != nil {
7686
bklog.G(ctx).WithError(err).Warnf("Failed to stat %q (parent of mount stub %q)", dir, p)
7787
continue
@@ -88,7 +98,7 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
8898
}
8999

90100
// Restore the timestamps of the dir
91-
if err := os.Chtimes(dir, atime, mtime); err != nil {
101+
if err := os.Chtimes(parent, atime, mtime); err != nil {
92102
bklog.G(ctx).WithError(err).Warnf("Failed to restore time time mount stub timestamp (os.Chtimes(%q, %v, %v))", dir, atime, mtime)
93103
}
94104
}

0 commit comments

Comments
 (0)