From 3f1673d6aa1a4fe3d8a561598ce1ce0687cb28f8 Mon Sep 17 00:00:00 2001 From: Aneesh Nireshwalia Date: Mon, 30 Jan 2023 21:03:27 -0700 Subject: [PATCH] Fix lint issues --- internal/backend/smb/config.go | 10 +++++----- internal/backend/smb/conpool.go | 8 ++++---- internal/backend/smb/smb.go | 28 ++++++++++------------------ 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/internal/backend/smb/config.go b/internal/backend/smb/config.go index af46e3dc3..6762ef955 100644 --- a/internal/backend/smb/config.go +++ b/internal/backend/smb/config.go @@ -27,14 +27,14 @@ type Config struct { IdleTimeout time.Duration `option:"idle-timeout" help:"Max time in seconds before closing idle connections. If no connections have been returned to the connection pool in the time given, the connection pool will be emptied. Set to 0 to keep connections indefinitely.(default: 60)"` RequireMessageSigning bool `option:"require-message-signing" help:"Mandates message signing otherwise does not allow the connection. If this is false, messaging signing is just enabled and not enforced. (default: false)"` Dialect uint16 `option:"dialect" help:"Force a specific dialect to be used. For SMB311 use '785', for SMB302 use '770', for SMB300 use '768', for SMB210 use '528', for SMB202 use '514', for SMB2 use '767'. If unspecfied (0), following dialects are tried in order - SMB311, SMB302, SMB300, SMB210, SMB202 (default: 0)"` - ClientGuid string `option:"client-guid" help:"A 16-byte GUID to uniquely identify a client. If not specific a random GUID is used. (default: \"\")"` + ClientGUID string `option:"client-guid" help:"A 16-byte GUID to uniquely identify a client. If not specific a random GUID is used. (default: \"\")"` } const ( - DefaultSmbPort int = 445 - DefaultDomain string = "WORKGROUP" - DefaultConnections uint = 2 - DefaultIdleTimeout time.Duration = 60 * time.Second + DefaultSmbPort int = 445 // DefaultSmbPort returns the default port for SMB + DefaultDomain string = "WORKGROUP" // DefaultDomain returns the default domain for SMB + DefaultConnections uint = 2 // DefaultConnections returns the number of concurrent connections for SMB. + DefaultIdleTimeout time.Duration = 60 * time.Second // DefaultIdleTimeout returns the default max time before closing idle connections for SMB. ) // NewConfig returns a new Config with the default values filled in. diff --git a/internal/backend/smb/conpool.go b/internal/backend/smb/conpool.go index 540609f7e..b6cbbf769 100644 --- a/internal/backend/smb/conpool.go +++ b/internal/backend/smb/conpool.go @@ -70,16 +70,16 @@ func (b *Backend) dial(ctx context.Context, network, addr string) (*conn, error) if err != nil { return nil, err } - var clientId [16]byte - if b.ClientGuid != "" { - copy(clientId[:], []byte(b.ClientGuid)) + var clientID [16]byte + if b.ClientGUID != "" { + copy(clientID[:], []byte(b.ClientGUID)) } d := &smb2.Dialer{ Negotiator: smb2.Negotiator{ RequireMessageSigning: b.RequireMessageSigning, SpecifiedDialect: b.Dialect, - ClientGuid: clientId, + ClientGuid: clientID, }, Initiator: &smb2.NTLMInitiator{ User: b.User, diff --git a/internal/backend/smb/smb.go b/internal/backend/smb/smb.go index bbbba65e4..b8f8ab2a1 100644 --- a/internal/backend/smb/smb.go +++ b/internal/backend/smb/smb.go @@ -149,7 +149,7 @@ func (b *Backend) IsNotExist(err error) bool { } // Join combines path components with slashes. -func (be *Backend) Join(p ...string) string { +func (b *Backend) Join(p ...string) string { return path.Join(p...) } @@ -366,9 +366,9 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi basedir, subdirs := b.Basedir(t) if subdirs { - err = b.visitDirs(cn, ctx, basedir, fn) + err = b.visitDirs(ctx, cn, basedir, fn) } else { - err = b.visitFiles(cn, ctx, basedir, fn, false) + err = b.visitFiles(ctx, cn, basedir, fn, false) } if b.IsNotExist(err) { @@ -383,7 +383,7 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi // two levels of directory structure (including dir itself as the first level). // Also, visitDirs assumes it sees a directory full of directories, while // visitFiles wants a directory full or regular files. -func (b *Backend) visitDirs(cn *conn, ctx context.Context, dir string, fn func(restic.FileInfo) error) error { +func (b *Backend) visitDirs(ctx context.Context, cn *conn, dir string, fn func(restic.FileInfo) error) error { d, err := cn.smbShare.Open(dir) if err != nil { return err @@ -402,7 +402,7 @@ func (b *Backend) visitDirs(cn *conn, ctx context.Context, dir string, fn func(r } for _, f := range sub { - err = b.visitFiles(cn, ctx, filepath.Join(dir, f), fn, true) + err = b.visitFiles(ctx, cn, filepath.Join(dir, f), fn, true) if err != nil { return err } @@ -410,7 +410,7 @@ func (b *Backend) visitDirs(cn *conn, ctx context.Context, dir string, fn func(r return ctx.Err() } -func (b *Backend) visitFiles(cn *conn, ctx context.Context, dir string, fn func(restic.FileInfo) error, ignoreNotADirectory bool) error { +func (b *Backend) visitFiles(ctx context.Context, cn *conn, dir string, fn func(restic.FileInfo) error, ignoreNotADirectory bool) error { d, err := cn.smbShare.Open(dir) if err != nil { return err @@ -473,16 +473,8 @@ func (b *Backend) Close() error { return err } -var ( - ErrExist = fs.ErrExist // "file already exists" -) - -// PathError records an error and the operation and file path that caused it. -type PathError = fs.PathError - const ( - PathSeparator = '/' // OS-specific path separator - PathListSeparator = ';' // OS-specific path list separator + pathSeparator = '/' // Always using '/' for SMB ) // CreateTemp creates a new temporary file in the directory dir, @@ -500,7 +492,7 @@ func (b *Backend) CreateTemp(cn *conn, dir, pattern string) (*smb2.File, error) prefix, suffix, err := prefixAndSuffix(pattern) if err != nil { - return nil, &PathError{Op: "createtemp", Path: pattern, Err: err} + return nil, &fs.PathError{Op: "createtemp", Path: pattern, Err: err} } prefix = joinPath(dir, prefix) @@ -513,7 +505,7 @@ func (b *Backend) CreateTemp(cn *conn, dir, pattern string) (*smb2.File, error) if try++; try < 10000 { continue } - return nil, &PathError{Op: "createtemp", Path: prefix + "*" + suffix, Err: ErrExist} + return nil, &fs.PathError{Op: "createtemp", Path: prefix + "*" + suffix, Err: fs.ErrExist} } return f, err } @@ -555,7 +547,7 @@ func joinPath(dir, name string) string { if len(dir) > 0 && IsPathSeparator(dir[len(dir)-1]) { return dir + name } - return dir + string(PathSeparator) + name + return dir + string(pathSeparator) + name } // IsPathSeparator reports whether c is a directory separator character.