5
5
"errors"
6
6
"os"
7
7
"path/filepath"
8
+ "strings"
8
9
"syscall"
9
10
10
11
"github.com/containerd/continuity/fs"
@@ -43,7 +44,7 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
43
44
}
44
45
45
46
realPathNext := filepath .Dir (realPath )
46
- if realPath == realPathNext {
47
+ if realPath == realPathNext || realPathNext == dir {
47
48
break
48
49
}
49
50
realPath = realPathNext
@@ -52,6 +53,11 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
52
53
53
54
return func () {
54
55
for _ , p := range paths {
56
+ p , err := fs .RootPath (dir , strings .TrimPrefix (p , dir ))
57
+ if err != nil {
58
+ continue
59
+ }
60
+
55
61
st , err := os .Lstat (p )
56
62
if err != nil {
57
63
continue
@@ -70,8 +76,12 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
70
76
71
77
// Back up the timestamps of the dir for reproducible builds
72
78
// 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 )
75
85
if err != nil {
76
86
bklog .G (ctx ).WithError (err ).Warnf ("Failed to stat %q (parent of mount stub %q)" , dir , p )
77
87
continue
@@ -88,7 +98,7 @@ func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursiv
88
98
}
89
99
90
100
// 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 {
92
102
bklog .G (ctx ).WithError (err ).Warnf ("Failed to restore time time mount stub timestamp (os.Chtimes(%q, %v, %v))" , dir , atime , mtime )
93
103
}
94
104
}
0 commit comments