lib/fs: Correct wrapping order for meaningful log-caller (#7209)

This commit is contained in:
Simon Frei
2020-12-21 13:01:34 +01:00
committed by GitHub
parent 78bd0341a8
commit a744dee94c
5 changed files with 56 additions and 40 deletions
+16 -1
View File
@@ -260,6 +260,21 @@ func Canonicalize(file string) (string, error) {
return file, nil
}
// wrapFilesystem should always be used when wrapping a Filesystem.
// It ensures proper wrapping order, which right now means:
// `logFilesystem` needs to be the outermost wrapper for caller lookup.
func wrapFilesystem(fs Filesystem, wrapFn func(Filesystem) Filesystem) Filesystem {
logFs, ok := fs.(*logFilesystem)
if ok {
fs = logFs.Filesystem
}
fs = wrapFn(fs)
if ok {
fs = &logFilesystem{fs}
}
return fs
}
// unwrapFilesystem removes "wrapping" filesystems to expose the underlying filesystem.
func unwrapFilesystem(fs Filesystem) Filesystem {
for {
@@ -268,7 +283,7 @@ func unwrapFilesystem(fs Filesystem) Filesystem {
fs = sfs.Filesystem
case *walkFilesystem:
fs = sfs.Filesystem
case *MtimeFS:
case *mtimeFS:
fs = sfs.Filesystem
default:
return sfs