Skip to content

Commit 8a3e584

Browse files
imsodincalmh
authored andcommitted
lib/fs: Introduce walkfs debug facility (syncthing#4712)
1 parent 043b04d commit 8a3e584

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/fs/debug.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ var (
1818
)
1919

2020
func init() {
21-
l.SetDebug("fs", strings.Contains(os.Getenv("STTRACE"), "fs") || os.Getenv("STTRACE") == "all")
21+
logger.DefaultLogger.NewFacility("walkfs", "Filesystem access while walking")
22+
switch {
23+
case strings.Contains(os.Getenv("STTRACE"), "walkfs") || os.Getenv("STTRACE") == "all":
24+
l.SetDebug("walkfs", true)
25+
fallthrough
26+
case strings.Contains(os.Getenv("STTRACE"), "fs"):
27+
l.SetDebug("fs", true)
28+
}
2229
}

lib/fs/filesystem.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func NewFilesystem(fsType FilesystemType, uri string) Filesystem {
160160
var fs Filesystem
161161
switch fsType {
162162
case FilesystemTypeBasic:
163-
fs = NewWalkFilesystem(newBasicFilesystem(uri))
163+
fs = newBasicFilesystem(uri)
164164
default:
165165
l.Debugln("Unknown filesystem", fsType, uri)
166166
fs = &errorFilesystem{
@@ -170,10 +170,15 @@ func NewFilesystem(fsType FilesystemType, uri string) Filesystem {
170170
}
171171
}
172172

173+
if l.ShouldDebug("walkfs") {
174+
return NewWalkFilesystem(&logFilesystem{fs})
175+
}
176+
173177
if l.ShouldDebug("fs") {
174-
fs = &logFilesystem{fs}
178+
return &logFilesystem{NewWalkFilesystem(fs)}
175179
}
176-
return fs
180+
181+
return NewWalkFilesystem(fs)
177182
}
178183

179184
// IsInternal returns true if the file, as a path relative to the folder

0 commit comments

Comments
 (0)