mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:32:29 +08:00
vfs: add debug dump function to dump the state of the VFS cache
This commit is contained in:
parent
9deab5a563
commit
c72d2c67ed
42
vfs/dir.go
42
vfs/dir.go
|
@ -2,6 +2,7 @@ package vfs
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
|
@ -74,6 +75,47 @@ func (d *Dir) String() string {
|
|||
return d.path + "/"
|
||||
}
|
||||
|
||||
// Dumps the directory tree to the string builder with the given indent
|
||||
func (d *Dir) dumpIndent(out *strings.Builder, indent string) {
|
||||
if d == nil {
|
||||
fmt.Fprintf(out, "%s<nil *Dir>\n", indent)
|
||||
return
|
||||
}
|
||||
d.mu.RLock()
|
||||
defer d.mu.RUnlock()
|
||||
fmt.Fprintf(out, "%sPath: %s\n", indent, d.path)
|
||||
fmt.Fprintf(out, "%sEntry: %v\n", indent, d.entry)
|
||||
fmt.Fprintf(out, "%sRead: %v\n", indent, d.read)
|
||||
fmt.Fprintf(out, "%s- items %d\n", indent, len(d.items))
|
||||
// Sort?
|
||||
for leaf, node := range d.items {
|
||||
switch x := node.(type) {
|
||||
case *Dir:
|
||||
fmt.Fprintf(out, "%s %s/ - %v\n", indent, leaf, x)
|
||||
// check the parent is correct
|
||||
if x.parent != d {
|
||||
fmt.Fprintf(out, "%s PARENT POINTER WRONG\n", indent)
|
||||
}
|
||||
x.dumpIndent(out, indent+"\t")
|
||||
case *File:
|
||||
fmt.Fprintf(out, "%s %s - %v\n", indent, leaf, x)
|
||||
default:
|
||||
panic("bad dir entry")
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(out, "%s- virtual %d\n", indent, len(d.virtual))
|
||||
for leaf, state := range d.virtual {
|
||||
fmt.Fprintf(out, "%s %s - %v\n", indent, leaf, state)
|
||||
}
|
||||
}
|
||||
|
||||
// Dumps a nicely formatted directory tree to a string
|
||||
func (d *Dir) dump() string {
|
||||
var out strings.Builder
|
||||
d.dumpIndent(&out, "")
|
||||
return out.String()
|
||||
}
|
||||
|
||||
// IsFile returns false for Dir - satisfies Node interface
|
||||
func (d *Dir) IsFile() bool {
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue
Block a user