@@ -101,6 +101,13 @@ func remount(m mounter, src, dest string) error {
101
101
if err := m .MkdirAll (destDir , 0o750 ); err != nil {
102
102
return fmt .Errorf ("ensure path: %w" , err )
103
103
}
104
+ if ! stat .IsDir () {
105
+ f , err := m .OpenFile (dest , os .O_CREATE , 0o640 )
106
+ if err != nil {
107
+ return fmt .Errorf ("ensure file path: %w" , err )
108
+ }
109
+ defer f .Close ()
110
+ }
104
111
if err := m .Mount (src , dest , "bind" , syscall .MS_BIND , "" ); err != nil {
105
112
return fmt .Errorf ("bind mount %s => %s: %w" , src , dest , err )
106
113
}
@@ -114,14 +121,16 @@ func remount(m mounter, src, dest string) error {
114
121
type mounter interface {
115
122
// GetMounts wraps procfs.GetMounts
116
123
GetMounts () ([]* procfs.MountInfo , error )
124
+ // Stat wraps os.Stat
125
+ Stat (string ) (os.FileInfo , error )
117
126
// MkdirAll wraps os.MkdirAll
118
127
MkdirAll (string , os.FileMode ) error
128
+ // OpenFile wraps os.OpenFile
129
+ OpenFile (string , int , os.FileMode ) (* os.File , error )
119
130
// Mount wraps syscall.Mount
120
131
Mount (string , string , string , uintptr , string ) error
121
132
// Unmount wraps syscall.Unmount
122
133
Unmount (string , int ) error
123
- // Stat wraps os.Stat
124
- Stat (string ) (os.FileInfo , error )
125
134
}
126
135
127
136
// realMounter implements mounter and actually does the thing.
@@ -145,6 +154,10 @@ func (m *realMounter) MkdirAll(path string, perm os.FileMode) error {
145
154
return os .MkdirAll (path , perm )
146
155
}
147
156
157
+ func (m * realMounter ) OpenFile (name string , flag int , perm os.FileMode ) (* os.File , error ) {
158
+ return os .OpenFile (name , flag , perm )
159
+ }
160
+
148
161
func (m * realMounter ) Stat (path string ) (os.FileInfo , error ) {
149
162
return os .Stat (path )
150
163
}
0 commit comments