11package chroot
22
33import (
4+ "errors"
45 "io/fs"
56 "os"
67 "path/filepath"
@@ -126,7 +127,12 @@ func (fs *ChrootHelper) TempFile(dir, prefix string) (billy.File, error) {
126127 return nil , err
127128 }
128129
129- f , err := fs .underlying .(billy.TempFile ).TempFile (fullpath , prefix )
130+ tf , ok := fs .underlying .(billy.TempFile )
131+ if ! ok {
132+ return nil , errors .New ("underlying fs does not implement billy.TempFile" )
133+ }
134+
135+ f , err := tf .TempFile (fullpath , prefix )
130136 if err != nil {
131137 return nil , err
132138 }
@@ -140,7 +146,11 @@ func (fs *ChrootHelper) ReadDir(path string) ([]fs.DirEntry, error) {
140146 return nil , err
141147 }
142148
143- return fs .underlying .(billy.Dir ).ReadDir (fullpath )
149+ d , ok := fs .underlying .(billy.Dir )
150+ if ! ok {
151+ return nil , errors .New ("underlying fs does not implement billy.Dir" )
152+ }
153+ return d .ReadDir (fullpath )
144154}
145155
146156func (fs * ChrootHelper ) MkdirAll (filename string , perm fs.FileMode ) error {
@@ -149,7 +159,11 @@ func (fs *ChrootHelper) MkdirAll(filename string, perm fs.FileMode) error {
149159 return err
150160 }
151161
152- return fs .underlying .(billy.Dir ).MkdirAll (fullpath , perm )
162+ d , ok := fs .underlying .(billy.Dir )
163+ if ! ok {
164+ return errors .New ("underlying fs does not implement billy.Dir" )
165+ }
166+ return d .MkdirAll (fullpath , perm )
153167}
154168
155169func (fs * ChrootHelper ) Lstat (filename string ) (os.FileInfo , error ) {
@@ -158,7 +172,11 @@ func (fs *ChrootHelper) Lstat(filename string) (os.FileInfo, error) {
158172 return nil , err
159173 }
160174
161- return fs .underlying .(billy.Symlink ).Lstat (fullpath )
175+ sl , ok := fs .underlying .(billy.Symlink )
176+ if ! ok {
177+ return nil , errors .New ("underlying fs does not implement billy.Symlink" )
178+ }
179+ return sl .Lstat (fullpath )
162180}
163181
164182func (fs * ChrootHelper ) Symlink (target , link string ) error {
@@ -175,7 +193,11 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
175193 return err
176194 }
177195
178- return fs .underlying .(billy.Symlink ).Symlink (target , link )
196+ sl , ok := fs .underlying .(billy.Symlink )
197+ if ! ok {
198+ return errors .New ("underlying fs does not implement billy.Symlink" )
199+ }
200+ return sl .Symlink (target , link )
179201}
180202
181203func (fs * ChrootHelper ) Readlink (link string ) (string , error ) {
@@ -184,7 +206,12 @@ func (fs *ChrootHelper) Readlink(link string) (string, error) {
184206 return "" , err
185207 }
186208
187- target , err := fs .underlying .(billy.Symlink ).Readlink (fullpath )
209+ sl , ok := fs .underlying .(billy.Symlink )
210+ if ! ok {
211+ return "" , errors .New ("underlying fs does not implement billy.Symlink" )
212+ }
213+
214+ target , err := sl .Readlink (fullpath )
188215 if err != nil {
189216 return "" , err
190217 }
0 commit comments