forked from TrueCloudLab/rclone
lib/dircache: add a way to dump the DirCache for debugging
This commit is contained in:
parent
159f2e29a8
commit
40cc8180f0
1 changed files with 27 additions and 0 deletions
|
@ -4,7 +4,9 @@ package dircache
|
||||||
// _methods are called without the lock
|
// _methods are called without the lock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -47,6 +49,31 @@ func New(root string, trueRootID string, fs DirCacher) *DirCache {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the directory cache in string form for debugging
|
||||||
|
func (dc *DirCache) String() string {
|
||||||
|
dc.cacheMu.RLock()
|
||||||
|
defer dc.cacheMu.RUnlock()
|
||||||
|
var buf bytes.Buffer
|
||||||
|
_, _ = buf.WriteString("DirCache{\n")
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\ttrueRootID: %q,\n", dc.trueRootID)
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\troot: %q,\n", dc.root)
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\trootID: %q,\n", dc.rootID)
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\trootParentID: %q,\n", dc.rootParentID)
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\tfoundRoot: %v,\n", dc.foundRoot)
|
||||||
|
_, _ = buf.WriteString("\tcache: {\n")
|
||||||
|
for k, v := range dc.cache {
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\t\t%q: %q,\n", k, v)
|
||||||
|
}
|
||||||
|
_, _ = buf.WriteString("\t},\n")
|
||||||
|
_, _ = buf.WriteString("\tinvCache: {\n")
|
||||||
|
for k, v := range dc.invCache {
|
||||||
|
_, _ = fmt.Fprintf(&buf, "\t\t%q: %q,\n", k, v)
|
||||||
|
}
|
||||||
|
_, _ = buf.WriteString("\t},\n")
|
||||||
|
_, _ = buf.WriteString("}\n")
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
// Get an ID given a path
|
// Get an ID given a path
|
||||||
func (dc *DirCache) Get(path string) (id string, ok bool) {
|
func (dc *DirCache) Get(path string) (id string, ok bool) {
|
||||||
dc.cacheMu.RLock()
|
dc.cacheMu.RLock()
|
||||||
|
|
Loading…
Reference in a new issue