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

build: fix linting issues reported by running golangci-lint with different GOOS

albertony7ee22fcdf96f
diff --git a/backend/azureblob/azureblob_unsupported.go b/backend/azureblob/azureblob_unsupported.go
index b5ccf8643..50fcea34c 100644
--- a/backend/azureblob/azureblob_unsupported.go
+++ b/backend/azureblob/azureblob_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9 || solaris || js
+// Package azureblob provides an interface to the Microsoft Azure blob object storage system
package azureblob
diff --git a/backend/azurefiles/azurefiles_unsupported.go b/backend/azurefiles/azurefiles_unsupported.go
index f261676fd..d2723e62f 100644
--- a/backend/azurefiles/azurefiles_unsupported.go
+++ b/backend/azurefiles/azurefiles_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9 || js
+// Package azurefiles provides an interface to Microsoft Azure Files
package azurefiles
diff --git a/backend/cache/cache_unsupported.go b/backend/cache/cache_unsupported.go
index 8ce32ee66..8c94aaf26 100644
--- a/backend/cache/cache_unsupported.go
+++ b/backend/cache/cache_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9 || js
+// Package cache implements a virtual provider to cache existing remotes.
package cache
diff --git a/backend/cache/utils_test.go b/backend/cache/utils_test.go
index c02d86ce9..9f85b0155 100644
--- a/backend/cache/utils_test.go
+++ b/backend/cache/utils_test.go
@@ -1,3 +1,6 @@
+//go:build !plan9 && !js
+// +build !plan9,!js
+
package cache
import bolt "go.etcd.io/bbolt"
diff --git a/backend/hdfs/hdfs_unsupported.go b/backend/hdfs/hdfs_unsupported.go
index 02305691b..a14c7725c 100644
--- a/backend/hdfs/hdfs_unsupported.go
+++ b/backend/hdfs/hdfs_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9
+// Package hdfs provides an interface to the HDFS storage system.
package hdfs
diff --git a/backend/local/about_unix.go b/backend/local/about_unix.go
index 24134c794..f8dce54e4 100644
--- a/backend/local/about_unix.go
+++ b/backend/local/about_unix.go
@@ -23,9 +23,9 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
}
bs := int64(s.Bsize) // nolint: unconvert
usage := &fs.Usage{
- Total: fs.NewUsageValue(bs * int64(s.Blocks)), // quota of bytes that can be used
- Used: fs.NewUsageValue(bs * int64(s.Blocks-s.Bfree)), // bytes in use
- Free: fs.NewUsageValue(bs * int64(s.Bavail)), // bytes which can be uploaded before reaching the quota
+ Total: fs.NewUsageValue(bs * int64(s.Blocks)), //nolint: unconvert // quota of bytes that can be used
+ Used: fs.NewUsageValue(bs * int64(s.Blocks-s.Bfree)), //nolint: unconvert // bytes in use
+ Free: fs.NewUsageValue(bs * int64(s.Bavail)), //nolint: unconvert // bytes which can be uploaded before reaching the quota
}
return usage, nil
}
diff --git a/backend/local/metadata_other.go b/backend/local/metadata_other.go
index c32c89f26..dc6a5a736 100644
--- a/backend/local/metadata_other.go
+++ b/backend/local/metadata_other.go
@@ -1,4 +1,4 @@
-//go:build plan9 || js
+//go:build dragonfly || plan9 || js
package local
diff --git a/backend/local/xattr_unsupported.go b/backend/local/xattr_unsupported.go
index e63c25492..20c86d07a 100644
--- a/backend/local/xattr_unsupported.go
+++ b/backend/local/xattr_unsupported.go
@@ -1,6 +1,7 @@
+// The pkg/xattr module doesn't compile for openbsd or plan9
+
//go:build openbsd || plan9
-// The pkg/xattr module doesn't compile for openbsd or plan9
package local
import "github.com/rclone/rclone/fs"
diff --git a/backend/oracleobjectstorage/oracleobjectstorage_unsupported.go b/backend/oracleobjectstorage/oracleobjectstorage_unsupported.go
index 07d8fd242..ccbc39316 100644
--- a/backend/oracleobjectstorage/oracleobjectstorage_unsupported.go
+++ b/backend/oracleobjectstorage/oracleobjectstorage_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9 || solaris || js
+// Package oracleobjectstorage provides an interface to the OCI object storage system.
package oracleobjectstorage
diff --git a/backend/qingstor/qingstor_unsupported.go b/backend/qingstor/qingstor_unsupported.go
index 209d909bc..e16a2e80c 100644
--- a/backend/qingstor/qingstor_unsupported.go
+++ b/backend/qingstor/qingstor_unsupported.go
@@ -3,4 +3,6 @@
//go:build plan9 || js
+// Package qingstor provides an interface to QingStor object storage
+// Home: https://www.qingcloud.com/
package qingstor
diff --git a/backend/sftp/sftp_unsupported.go b/backend/sftp/sftp_unsupported.go
index 8dc950374..67794bc4f 100644
--- a/backend/sftp/sftp_unsupported.go
+++ b/backend/sftp/sftp_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9
+// Package sftp provides a filesystem interface using github.com/pkg/sftp
package sftp
diff --git a/backend/storj/storj_unsupported.go b/backend/storj/storj_unsupported.go
index 67f9ebdfd..c3c731594 100644
--- a/backend/storj/storj_unsupported.go
+++ b/backend/storj/storj_unsupported.go
@@ -1,3 +1,4 @@
//go:build plan9
+// Package storj provides an interface to Storj decentralized object storage.
package storj
diff --git a/cmd/cachestats/cachestats_unsupported.go b/cmd/cachestats/cachestats_unsupported.go
index 089ba751a..1ab469e91 100644
--- a/cmd/cachestats/cachestats_unsupported.go
+++ b/cmd/cachestats/cachestats_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9 || js
+// Package cachestats provides the cachestats command.
package cachestats
diff --git a/cmd/ncdu/ncdu_unsupported.go b/cmd/ncdu/ncdu_unsupported.go
index e1f6430c2..34d99ed6c 100644
--- a/cmd/ncdu/ncdu_unsupported.go
+++ b/cmd/ncdu/ncdu_unsupported.go
@@ -3,4 +3,5 @@
//go:build plan9 || js
+// Package ncdu implements a text based user interface for exploring a remote
package ncdu
diff --git a/cmd/serve/ftp/ftp_unsupported.go b/cmd/serve/ftp/ftp_unsupported.go
index 7fa857560..f4c5415db 100644
--- a/cmd/serve/ftp/ftp_unsupported.go
+++ b/cmd/serve/ftp/ftp_unsupported.go
@@ -3,9 +3,10 @@
//go:build plan9
+// Package ftp implements an FTP server for rclone
package ftp
import "github.com/spf13/cobra"
// Command definition is nil to show not implemented
-var Command *cobra.Command = nil
+var Command *cobra.Command
diff --git a/cmd/serve/sftp/sftp_unsupported.go b/cmd/serve/sftp/sftp_unsupported.go
index 9f0df6499..22e0673a7 100644
--- a/cmd/serve/sftp/sftp_unsupported.go
+++ b/cmd/serve/sftp/sftp_unsupported.go
@@ -3,9 +3,10 @@
//go:build plan9
+// Package sftp implements an SFTP server to serve an rclone VFS
package sftp
import "github.com/spf13/cobra"
// Command definition is nil to show not implemented
-var Command *cobra.Command = nil
+var Command *cobra.Command
diff --git a/fs/fserrors/enospc_error_notsupported.go b/fs/fserrors/enospc_error_notsupported.go
index 30f5a6b3c..f1f1e94de 100644
--- a/fs/fserrors/enospc_error_notsupported.go
+++ b/fs/fserrors/enospc_error_notsupported.go
@@ -2,7 +2,7 @@
package fserrors
-// IsErrNoSpace() on plan9 returns false because
+// IsErrNoSpace on plan9 returns false because
// plan9 does not support syscall.ENOSPC error.
func IsErrNoSpace(cause error) (isNoSpc bool) {
isNoSpc = false
diff --git a/fs/fserrors/error_syscall_test.go b/fs/fserrors/error_syscall_test.go
new file mode 100644
index 000000000..f2523b6fd
--- /dev/null
+++ b/fs/fserrors/error_syscall_test.go
@@ -0,0 +1,74 @@
+//go:build !plan9
+// +build !plan9
+
+package fserrors
+
+import (
+ "fmt"
+ "net"
+ "net/url"
+ "os"
+ "syscall"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// make a plausible network error with the underlying errno
+func makeNetErr(errno syscall.Errno) error {
+ return &net.OpError{
+ Op: "write",
+ Net: "tcp",
+ Source: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 123},
+ Addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8080},
+ Err: &os.SyscallError{
+ Syscall: "write",
+ Err: errno,
+ },
+ }
+}
+
+func TestWithSyscallCause(t *testing.T) {
+ for i, test := range []struct {
+ err error
+ wantRetriable bool
+ wantErr error
+ }{
+ {makeNetErr(syscall.EAGAIN), true, syscall.EAGAIN},
+ {makeNetErr(syscall.Errno(123123123)), false, syscall.Errno(123123123)},
+ } {
+ gotRetriable, gotErr := Cause(test.err)
+ what := fmt.Sprintf("test #%d: %v", i, test.err)
+ assert.Equal(t, test.wantErr, gotErr, what)
+ assert.Equal(t, test.wantRetriable, gotRetriable, what)
+ }
+}
+
+func TestWithSyscallShouldRetry(t *testing.T) {
+ for i, test := range []struct {
+ err error
+ want bool
+ }{
+ {makeNetErr(syscall.EAGAIN), true},
+ {makeNetErr(syscall.Errno(123123123)), false},
+ {
+ wrap(&url.Error{
+ Op: "post",
+ URL: "http://localhost/",
+ Err: makeNetErr(syscall.EPIPE),
+ }, "potato error"),
+ true,
+ },
+ {
+ wrap(&url.Error{
+ Op: "post",
+ URL: "http://localhost/",
+ Err: makeNetErr(syscall.Errno(123123123)),
+ }, "listing error"),
+ false,
+ },
+ } {
+ got := ShouldRetry(test.err)
+ assert.Equal(t, test.want, got, fmt.Sprintf("test #%d: %v", i, test.err))
+ }
+}
diff --git a/fs/fserrors/error_test.go b/fs/fserrors/error_test.go
index ec8426660..21bdaf5cb 100644
--- a/fs/fserrors/error_test.go
+++ b/fs/fserrors/error_test.go
@@ -5,10 +5,7 @@ import (
"errors"
"fmt"
"io"
- "net"
"net/url"
- "os"
- "syscall"
"testing"
"time"
@@ -41,20 +38,6 @@ func wrap(err error, message string) error {
var errUseOfClosedNetworkConnection = errors.New("use of closed network connection")
-// make a plausible network error with the underlying errno
-func makeNetErr(errno syscall.Errno) error {
- return &net.OpError{
- Op: "write",
- Net: "tcp",
- Source: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 123},
- Addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8080},
- Err: &os.SyscallError{
- Syscall: "write",
- Err: errno,
- },
- }
-}
-
type myError1 struct {
Err error
}
@@ -121,8 +104,6 @@ func TestCause(t *testing.T) {
{fmt.Errorf("potato: %w", errPotato), false, errPotato},
{fmt.Errorf("potato2: %w", wrap(errPotato, "potato")), false, errPotato},
{errUseOfClosedNetworkConnection, false, errUseOfClosedNetworkConnection},
- {makeNetErr(syscall.EAGAIN), true, syscall.EAGAIN},
- {makeNetErr(syscall.Errno(123123123)), false, syscall.Errno(123123123)},
{eNil1, false, eNil1},
{eNil2, false, eNil2.Err},
{myError1{io.EOF}, false, io.EOF},
@@ -151,27 +132,9 @@ func TestShouldRetry(t *testing.T) {
{fmt.Errorf("connection: %w", errUseOfClosedNetworkConnection), true},
{io.EOF, true},
{io.ErrUnexpectedEOF, true},
- {makeNetErr(syscall.EAGAIN), true},
- {makeNetErr(syscall.Errno(123123123)), false},
{&url.Error{Op: "post", URL: "/", Err: io.EOF}, true},
{&url.Error{Op: "post", URL: "/", Err: errUseOfClosedNetworkConnection}, true},
{&url.Error{Op: "post", URL: "/", Err: fmt.Errorf("net/http: HTTP/1.x transport connection broken: %v", fmt.Errorf("http: ContentLength=%d with Body length %d", 100663336, 99590598))}, true},
- {
- wrap(&url.Error{
- Op: "post",
- URL: "http://localhost/",
- Err: makeNetErr(syscall.EPIPE),
- }, "potato error"),
- true,
- },
- {
- wrap(&url.Error{
- Op: "post",
- URL: "http://localhost/",
- Err: makeNetErr(syscall.Errno(123123123)),
- }, "listing error"),
- false,
- },
} {
got := ShouldRetry(test.err)
assert.Equal(t, test.want, got, fmt.Sprintf("test #%d: %v", i, test.err))
diff --git a/fs/logger/logger_test.go b/fs/logger/logger_test.go
index 0e53563ce..d306cdd13 100644
--- a/fs/logger/logger_test.go
+++ b/fs/logger/logger_test.go
@@ -1,3 +1,6 @@
+//go:build !plan9
+// +build !plan9
+
package logger_test
import (
diff --git a/lib/kv/unsupported.go b/lib/kv/unsupported.go
index cf2f5d56a..c4bb0deff 100644
--- a/lib/kv/unsupported.go
+++ b/lib/kv/unsupported.go
@@ -1,5 +1,6 @@
//go:build plan9 || js
+// Package kv provides key/value database.
package kv
import (
diff --git a/vfs/vfstest/write_other.go b/vfs/vfstest/write_other.go
new file mode 100644
index 000000000..f95c3efa1
--- /dev/null
+++ b/vfs/vfstest/write_other.go
@@ -0,0 +1,20 @@
+//go:build !linux && !darwin && !freebsd && !windows
+// +build !linux,!darwin,!freebsd,!windows
+
+package vfstest
+
+import (
+ "errors"
+ "runtime"
+ "testing"
+)
+
+// TestWriteFileDoubleClose tests double close on write
+func TestWriteFileDoubleClose(t *testing.T) {
+ t.Skip("not supported on " + runtime.GOOS)
+}
+
+// writeTestDup performs the platform-specific implementation of the dup() unix
+func writeTestDup(oldfd uintptr) (uintptr, error) {
+ return 0, errors.New("not supported on " + runtime.GOOS)
+}
diff --git a/vfs/vfstest/write_non_unix.go b/vfs/vfstest/write_windows.go
similarity index 92%
rename from vfs/vfstest/write_non_unix.go
rename to vfs/vfstest/write_windows.go
index 161354434..227e302a3 100644
--- a/vfs/vfstest/write_non_unix.go
+++ b/vfs/vfstest/write_windows.go
@@ -1,4 +1,4 @@
-//go:build !linux && !darwin && !freebsd
+//go:build windows
package vfstest