From c1d5faa32a6c6fc158fbc5c6ddc6180d0de61f6e Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 8 May 2017 18:05:12 +0100 Subject: [PATCH] mountlib: fix code quality warnings --- cmd/mountlib/fs.go | 6 +++--- cmd/mountlib/mounttest/dir.go | 9 +++++++++ cmd/mountlib/mounttest/file.go | 2 ++ cmd/mountlib/mounttest/fs.go | 12 +++++++----- cmd/mountlib/mounttest/read.go | 5 +++-- cmd/mountlib/mounttest/write.go | 10 +++++----- cmd/mountlib/write.go | 2 +- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/cmd/mountlib/fs.go b/cmd/mountlib/fs.go index 911ab5593..0c0535cbd 100644 --- a/cmd/mountlib/fs.go +++ b/cmd/mountlib/fs.go @@ -78,8 +78,8 @@ func NewInode() (inode uint64) { } // Lookup finds the Node by path starting from the root -func (f *FS) Lookup(path string) (node Node, err error) { - node = f.root +func (fsys *FS) Lookup(path string) (node Node, err error) { + node = fsys.root for path != "" { i := strings.IndexRune(path, '/') var name string @@ -106,7 +106,7 @@ func (f *FS) Lookup(path string) (node Node, err error) { // Statfs is called to obtain file system metadata. // It should write that data to resp. -func (f *FS) Statfs() error { +func (fsys *FS) Statfs() error { /* FIXME const blockSize = 4096 const fsBlocks = (1 << 50) / blockSize diff --git a/cmd/mountlib/mounttest/dir.go b/cmd/mountlib/mounttest/dir.go index a1c52f328..03d088aa5 100644 --- a/cmd/mountlib/mounttest/dir.go +++ b/cmd/mountlib/mounttest/dir.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" ) +// TestDirLs checks out listing func TestDirLs(t *testing.T) { run.skipIfNoFUSE(t) @@ -26,6 +27,7 @@ func TestDirLs(t *testing.T) { run.checkDir(t, "") } +// TestDirCreateAndRemoveDir tests creating and removing a directory func TestDirCreateAndRemoveDir(t *testing.T) { run.skipIfNoFUSE(t) @@ -44,6 +46,7 @@ func TestDirCreateAndRemoveDir(t *testing.T) { run.checkDir(t, "") } +// TestDirCreateAndRemoveFile tests creating and removing a file func TestDirCreateAndRemoveFile(t *testing.T) { run.skipIfNoFUSE(t) @@ -63,6 +66,7 @@ func TestDirCreateAndRemoveFile(t *testing.T) { run.checkDir(t, "") } +// TestDirRenameFile tests renaming a file func TestDirRenameFile(t *testing.T) { run.skipIfNoFUSE(t) @@ -91,6 +95,7 @@ func TestDirRenameFile(t *testing.T) { run.checkDir(t, "") } +// TestDirRenameEmptyDir tests renaming and empty directory func TestDirRenameEmptyDir(t *testing.T) { run.skipIfNoFUSE(t) @@ -111,6 +116,7 @@ func TestDirRenameEmptyDir(t *testing.T) { run.checkDir(t, "") } +// TestDirRenameFullDir tests renaming a full directory func TestDirRenameFullDir(t *testing.T) { run.skipIfNoFUSE(t) @@ -133,6 +139,7 @@ func TestDirRenameFullDir(t *testing.T) { run.checkDir(t, "") } +// TestDirModTime tests mod times func TestDirModTime(t *testing.T) { run.skipIfNoFUSE(t) @@ -150,6 +157,7 @@ func TestDirModTime(t *testing.T) { run.rmdir(t, "dir") } +// TestDirCacheFlush tests fluching the dir cache func TestDirCacheFlush(t *testing.T) { run.skipIfNoFUSE(t) @@ -189,6 +197,7 @@ func TestDirCacheFlush(t *testing.T) { run.checkDir(t, "") } +// TestDirCacheFlushOnDirRename tests flushing the dir cache on rename func TestDirCacheFlushOnDirRename(t *testing.T) { run.skipIfNoFUSE(t) run.mkdir(t, "dir") diff --git a/cmd/mountlib/mounttest/file.go b/cmd/mountlib/mounttest/file.go index 5a03c528c..60db071db 100644 --- a/cmd/mountlib/mounttest/file.go +++ b/cmd/mountlib/mounttest/file.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" ) +// TestFileModTime tests mod times on files func TestFileModTime(t *testing.T) { run.skipIfNoFUSE(t) @@ -27,6 +28,7 @@ func TestFileModTime(t *testing.T) { run.rm(t, "file") } +// TestFileModTimeWithOpenWriters tests mod time on open files func TestFileModTimeWithOpenWriters(t *testing.T) { run.skipIfNoFUSE(t) diff --git a/cmd/mountlib/mounttest/fs.go b/cmd/mountlib/mounttest/fs.go index 6922e9aa6..9fe05cd5c 100644 --- a/cmd/mountlib/mounttest/fs.go +++ b/cmd/mountlib/mounttest/fs.go @@ -17,7 +17,7 @@ import ( "github.com/ncw/rclone/cmd/mountlib" "github.com/ncw/rclone/fs" - _ "github.com/ncw/rclone/fs/all" + _ "github.com/ncw/rclone/fs/all" // import all the file systems "github.com/ncw/rclone/fstest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,8 +35,10 @@ var ( ) type ( + // UnmountFn is called to unmount the file system UnmountFn func() error - MountFn func(f fs.Fs, mountpoint string) (*mountlib.FS, <-chan error, func() error, error) + // MountFn is called to mount the file system + MountFn func(f fs.Fs, mountpoint string) (*mountlib.FS, <-chan error, func() error, error) ) var ( @@ -294,8 +296,8 @@ func (r *Run) rmdir(t *testing.T, filepath string) { require.NoError(t, err) } -// Check that the Fs is mounted by seeing if the mountpoint is -// in the mount output +// TestMount checks that the Fs is mounted by seeing if the mountpoint +// is in the mount output func TestMount(t *testing.T) { run.skipIfNoFUSE(t) @@ -304,7 +306,7 @@ func TestMount(t *testing.T) { assert.Contains(t, string(out), run.mountPath) } -// Check root directory is present and correct +// TestRoot checks root directory is present and correct func TestRoot(t *testing.T) { run.skipIfNoFUSE(t) diff --git a/cmd/mountlib/mounttest/read.go b/cmd/mountlib/mounttest/read.go index 81a69eb61..6489841aa 100644 --- a/cmd/mountlib/mounttest/read.go +++ b/cmd/mountlib/mounttest/read.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" ) -// Read by byte including don't read any bytes +// TestReadByByte reads by byte including don't read any bytes func TestReadByByte(t *testing.T) { run.skipIfNoFUSE(t) @@ -34,6 +34,7 @@ func TestReadByByte(t *testing.T) { run.rm(t, "testfile") } +// TestReadChecksum checks the checksum reading is working func TestReadChecksum(t *testing.T) { run.skipIfNoFUSE(t) @@ -73,7 +74,7 @@ func TestReadChecksum(t *testing.T) { run.rm(t, "bigfile") } -// Test seeking +// TestReadSeek test seeking func TestReadSeek(t *testing.T) { run.skipIfNoFUSE(t) diff --git a/cmd/mountlib/mounttest/write.go b/cmd/mountlib/mounttest/write.go index fbf44c990..d28468763 100644 --- a/cmd/mountlib/mounttest/write.go +++ b/cmd/mountlib/mounttest/write.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" ) -// Test writing a file with no write()'s to it +// TestWriteFileNoWrite tests writing a file with no write()'s to it func TestWriteFileNoWrite(t *testing.T) { run.skipIfNoFUSE(t) @@ -27,7 +27,7 @@ func TestWriteFileNoWrite(t *testing.T) { run.rm(t, "testnowrite") } -// Test open file in directory listing +// FIXMETestWriteOpenFileInDirListing tests open file in directory listing func FIXMETestWriteOpenFileInDirListing(t *testing.T) { run.skipIfNoFUSE(t) @@ -42,7 +42,7 @@ func FIXMETestWriteOpenFileInDirListing(t *testing.T) { run.rm(t, "testnowrite") } -// Test writing a file and reading it back +// TestWriteFileWrite tests writing a file and reading it back func TestWriteFileWrite(t *testing.T) { run.skipIfNoFUSE(t) @@ -53,7 +53,7 @@ func TestWriteFileWrite(t *testing.T) { run.rm(t, "testwrite") } -// Test overwriting a file +// TestWriteFileOverwrite tests overwriting a file func TestWriteFileOverwrite(t *testing.T) { run.skipIfNoFUSE(t) @@ -65,7 +65,7 @@ func TestWriteFileOverwrite(t *testing.T) { run.rm(t, "testwrite") } -// Test Fsync +// TestWriteFileFsync tests Fsync // // NB the code for this is in file.go rather than write.go func TestWriteFileFsync(t *testing.T) { diff --git a/cmd/mountlib/write.go b/cmd/mountlib/write.go index 68c2221b4..e2dae039b 100644 --- a/cmd/mountlib/write.go +++ b/cmd/mountlib/write.go @@ -91,7 +91,7 @@ func (fh *WriteFileHandle) Write(data []byte, offset int64) (written int64, err return written, nil } -// Returns the offset of the file pointer +// Offset returns the offset of the file pointer func (fh *WriteFileHandle) Offset() (offset int64) { return fh.offset }