Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

mountlib: make Nodes also be fmt.Stringer so they debug nicely

Nick Craig-Woodabda616f8479
diff --git a/cmd/mountlib/dir.go b/cmd/mountlib/dir.go
index e9cd48bf6..67768f55d 100644
--- a/cmd/mountlib/dir.go
+++ b/cmd/mountlib/dir.go
@@ -44,6 +44,14 @@ func newDir(fsys *FS, f fs.Fs, fsDir *fs.Dir) *Dir {
}
}
+// String converts it to printablee
+func (d *Dir) String() string {
+ if d == nil {
+ return "<nil *Dir>"
+ }
+ return d.path + "/"
+}
+
// IsFile returns false for Dir - satisfies Node interface
func (d *Dir) IsFile() bool {
return false
@@ -252,7 +260,7 @@ func (d *Dir) lookupNode(leaf string) (item *DirEntry, err error) {
var node Node
switch x := item.Obj.(type) {
case fs.Object:
- node, err = newFile(d, x), nil
+ node, err = newFile(d, x, leaf), nil
case *fs.Dir:
node, err = newDir(d.fsys, d.f, x), nil
default:
@@ -308,7 +316,7 @@ func (d *Dir) Create(name string) (*File, *WriteFileHandle, error) {
fs.Debugf(path, "Dir.Create")
src := newCreateInfo(d.f, path)
// This gets added to the directory when the file is written
- file := newFile(d, nil)
+ file := newFile(d, nil, name)
fh, err := newWriteFileHandle(d, file, src)
if err != nil {
fs.Errorf(path, "Dir.Create error: %v", err)
diff --git a/cmd/mountlib/file.go b/cmd/mountlib/file.go
index 07cc67d22..5a6531c0e 100644
--- a/cmd/mountlib/file.go
+++ b/cmd/mountlib/file.go
@@ -1,6 +1,7 @@
package mountlib
import (
+ "path"
"sync"
"sync/atomic"
"time"
@@ -16,19 +17,29 @@ type File struct {
d *Dir // parent directory - read only
mu sync.RWMutex // protects the following
o fs.Object // NB o may be nil if file is being written
+ leaf string // leaf name of the object
writers int // number of writers for this file
pendingModTime time.Time // will be applied once o becomes available, i.e. after file was written
}
// newFile creates a new File
-func newFile(d *Dir, o fs.Object) *File {
+func newFile(d *Dir, o fs.Object, leaf string) *File {
return &File{
d: d,
o: o,
+ leaf: leaf,
inode: NewInode(),
}
}
+// String converts it to printable
+func (f *File) String() string {
+ if f == nil {
+ return "<nil *File>"
+ }
+ return path.Join(f.d.path, f.leaf)
+}
+
// IsFile returns true for File - satisfies Node interface
func (f *File) IsFile() bool {
return true
diff --git a/cmd/mountlib/fs.go b/cmd/mountlib/fs.go
index 0c0535cbd..ebf1438b0 100644
--- a/cmd/mountlib/fs.go
+++ b/cmd/mountlib/fs.go
@@ -1,6 +1,7 @@
package mountlib
import (
+ "fmt"
"strings"
"sync/atomic"
"time"
@@ -21,6 +22,7 @@ var (
// Noder represents something which can return a node
type Noder interface {
+ fmt.Stringer
Node() Node
}
diff --git a/cmd/mountlib/read.go b/cmd/mountlib/read.go
index f97216d36..5c3535e5e 100644
--- a/cmd/mountlib/read.go
+++ b/cmd/mountlib/read.go
@@ -46,6 +46,17 @@ func newReadFileHandle(f *File, o fs.Object) (*ReadFileHandle, error) {
return fh, nil
}
+// String converts it to printable
+func (fh *ReadFileHandle) String() string {
+ if fh == nil {
+ return "<nil *ReadFileHandle>"
+ }
+ if fh.file == nil {
+ return "<nil *ReadFileHandle.file>"
+ }
+ return fh.file.String() + " (r)"
+}
+
// Node returns the Node assocuated with this - satisfies Noder interface
func (fh *ReadFileHandle) Node() Node {
return fh.file
diff --git a/cmd/mountlib/write.go b/cmd/mountlib/write.go
index e2dae039b..524ec4c08 100644
--- a/cmd/mountlib/write.go
+++ b/cmd/mountlib/write.go
@@ -52,6 +52,17 @@ func newWriteFileHandle(d *Dir, f *File, src fs.ObjectInfo) (*WriteFileHandle, e
return fh, nil
}
+// String converts it to printable
+func (fh *WriteFileHandle) String() string {
+ if fh == nil {
+ return "<nil *WriteFileHandle>"
+ }
+ if fh.file == nil {
+ return "<nil *WriteFileHandle.file>"
+ }
+ return fh.file.String() + " (w)"
+}
+
// Node returns the Node assocuated with this - satisfies Noder interface
func (fh *WriteFileHandle) Node() Node {
return fh.file