From 512f4b4487d5210b899624f10215fcd91be0527f Mon Sep 17 00:00:00 2001
From: Nick Craig-Wood <nick@craig-wood.com>
Date: Tue, 22 May 2018 09:41:13 +0100
Subject: [PATCH] Update error checking on fmt.Fprint* after errcheck update

Now we need to check or ignore errors on fmt.Fprint* explicitly -
previously errcheck just ignored them for us.
---
 backend/sftp/sftp.go              |  2 +-
 cmd/cmd.go                        |  6 +++---
 cmd/lsf/lsf.go                    |  2 +-
 cmd/tree/tree.go                  |  2 +-
 fs/accounting/stats.go            |  6 +++---
 fs/config/config.go               | 16 ++++++++--------
 fs/config/config_read_password.go |  2 +-
 fs/walk/walk.go                   |  4 ++--
 lib/oauthutil/oauthutil.go        |  8 ++++----
 9 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go
index 8e4eb905e..1fe1553f7 100644
--- a/backend/sftp/sftp.go
+++ b/backend/sftp/sftp.go
@@ -340,7 +340,7 @@ func NewFs(name, root string) (fs.Fs, error) {
 
 	// Ask for password if none was defined and we're allowed to
 	if pass == "" && *sftpAskPassword {
-		fmt.Fprint(os.Stderr, "Enter SFTP password: ")
+		_, _ = fmt.Fprint(os.Stderr, "Enter SFTP password: ")
 		clearpass := config.ReadPassword()
 		sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass))
 	}
diff --git a/cmd/cmd.go b/cmd/cmd.go
index c71472904..0c79f7ea8 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -122,7 +122,7 @@ func runRoot(cmd *cobra.Command, args []string) {
 		resolveExitCode(nil)
 	} else {
 		_ = Root.Usage()
-		fmt.Fprintf(os.Stderr, "Command not found.\n")
+		_, _ = fmt.Fprintf(os.Stderr, "Command not found.\n")
 		resolveExitCode(errorCommandNotFound)
 	}
 }
@@ -368,12 +368,12 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
 func CheckArgs(MinArgs, MaxArgs int, cmd *cobra.Command, args []string) {
 	if len(args) < MinArgs {
 		_ = cmd.Usage()
-		fmt.Fprintf(os.Stderr, "Command %s needs %d arguments minimum\n", cmd.Name(), MinArgs)
+		_, _ = fmt.Fprintf(os.Stderr, "Command %s needs %d arguments minimum\n", cmd.Name(), MinArgs)
 		// os.Exit(1)
 		resolveExitCode(errorNotEnoughArguments)
 	} else if len(args) > MaxArgs {
 		_ = cmd.Usage()
-		fmt.Fprintf(os.Stderr, "Command %s needs %d arguments maximum\n", cmd.Name(), MaxArgs)
+		_, _ = fmt.Fprintf(os.Stderr, "Command %s needs %d arguments maximum\n", cmd.Name(), MaxArgs)
 		// os.Exit(1)
 		resolveExitCode(errorTooManyArguents)
 	}
diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.go
index ee5dd2aae..d6dfe2458 100644
--- a/cmd/lsf/lsf.go
+++ b/cmd/lsf/lsf.go
@@ -186,7 +186,7 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
 					continue
 				}
 			}
-			fmt.Fprintln(out, list.Format(entry))
+			_, _ = fmt.Fprintln(out, list.Format(entry))
 		}
 		return nil
 	})
diff --git a/cmd/tree/tree.go b/cmd/tree/tree.go
index 86fdefd1e..e451df7b5 100644
--- a/cmd/tree/tree.go
+++ b/cmd/tree/tree.go
@@ -135,7 +135,7 @@ func Tree(fsrc fs.Fs, outFile io.Writer, opts *tree.Options) error {
 		if !opts.DirsOnly {
 			footer += fmt.Sprintf(", %d files", nf)
 		}
-		fmt.Fprintln(outFile, footer)
+		_, _ = fmt.Fprintln(outFile, footer)
 	}
 	return nil
 }
diff --git a/fs/accounting/stats.go b/fs/accounting/stats.go
index 8eabb12cc..ca0f3084c 100644
--- a/fs/accounting/stats.go
+++ b/fs/accounting/stats.go
@@ -62,7 +62,7 @@ func (s *StatsInfo) String() string {
 		speed = speed * 8
 	}
 
-	fmt.Fprintf(buf, `
+	_, _ = fmt.Fprintf(buf, `
 Transferred:   %10s (%s)
 Errors:        %10d
 Checks:        %10d
@@ -80,10 +80,10 @@ Elapsed time:  %10v
 	s.mu.RUnlock()
 
 	if !s.checking.empty() {
-		fmt.Fprintf(buf, "Checking:\n%s\n", s.checking)
+		_, _ = fmt.Fprintf(buf, "Checking:\n%s\n", s.checking)
 	}
 	if !s.transferring.empty() {
-		fmt.Fprintf(buf, "Transferring:\n%s\n", s.transferring)
+		_, _ = fmt.Fprintf(buf, "Transferring:\n%s\n", s.transferring)
 	}
 	return buf.String()
 }
diff --git a/fs/config/config.go b/fs/config/config.go
index 838989f6d..3cdac4fe3 100644
--- a/fs/config/config.go
+++ b/fs/config/config.go
@@ -275,7 +275,7 @@ func checkPassword(password string) (string, error) {
 	trimmedPassword := strings.TrimSpace(password)
 	// Warn user if password has leading+trailing whitespace
 	if len(password) != len(trimmedPassword) {
-		fmt.Fprintln(os.Stderr, "Your password contains leading/trailing whitespace - in previous versions of rclone this was stripped")
+		_, _ = fmt.Fprintln(os.Stderr, "Your password contains leading/trailing whitespace - in previous versions of rclone this was stripped")
 	}
 	// Normalize to reduce weird variations.
 	password = norm.NFKC.String(password)
@@ -287,15 +287,15 @@ func checkPassword(password string) (string, error) {
 
 // GetPassword asks the user for a password with the prompt given.
 func GetPassword(prompt string) string {
-	fmt.Fprintln(os.Stderr, prompt)
+	_, _ = fmt.Fprintln(os.Stderr, prompt)
 	for {
-		fmt.Fprint(os.Stderr, "password:")
+		_, _ = fmt.Fprint(os.Stderr, "password:")
 		password := ReadPassword()
 		password, err := checkPassword(password)
 		if err == nil {
 			return password
 		}
-		fmt.Fprintf(os.Stderr, "Bad password: %v\n", err)
+		_, _ = fmt.Fprintf(os.Stderr, "Bad password: %v\n", err)
 	}
 }
 
@@ -324,7 +324,7 @@ func getConfigPassword(q string) {
 		if err == nil {
 			return
 		}
-		fmt.Fprintln(os.Stderr, "Error:", err)
+		_, _ = fmt.Fprintln(os.Stderr, "Error:", err)
 	}
 }
 
@@ -382,9 +382,9 @@ func saveConfig() error {
 			return errors.Errorf("Failed to write temp config file: %v", err)
 		}
 	} else {
-		fmt.Fprintln(f, "# Encrypted rclone configuration File")
-		fmt.Fprintln(f, "")
-		fmt.Fprintln(f, "RCLONE_ENCRYPT_V0:")
+		_, _ = fmt.Fprintln(f, "# Encrypted rclone configuration File")
+		_, _ = fmt.Fprintln(f, "")
+		_, _ = fmt.Fprintln(f, "RCLONE_ENCRYPT_V0:")
 
 		// Generate new nonce and write it to the start of the ciphertext
 		var nonce [24]byte
diff --git a/fs/config/config_read_password.go b/fs/config/config_read_password.go
index aadc2b275..26f4d11ac 100644
--- a/fs/config/config_read_password.go
+++ b/fs/config/config_read_password.go
@@ -17,7 +17,7 @@ import (
 // ReadPassword reads a password without echoing it to the terminal.
 func ReadPassword() string {
 	line, err := terminal.ReadPassword(int(os.Stdin.Fd()))
-	fmt.Fprintln(os.Stderr)
+	_, _ = fmt.Fprintln(os.Stderr)
 	if err != nil {
 		log.Fatalf("Failed to read password: %v", err)
 	}
diff --git a/fs/walk/walk.go b/fs/walk/walk.go
index 6faeff34e..d92a21e9f 100644
--- a/fs/walk/walk.go
+++ b/fs/walk/walk.go
@@ -337,13 +337,13 @@ func (dt DirTree) Prune(dirNames map[string]bool) error {
 func (dt DirTree) String() string {
 	out := new(bytes.Buffer)
 	for _, dir := range dt.Dirs() {
-		fmt.Fprintf(out, "%s/\n", dir)
+		_, _ = fmt.Fprintf(out, "%s/\n", dir)
 		for _, entry := range dt[dir] {
 			flag := ""
 			if _, ok := entry.(fs.Directory); ok {
 				flag = "/"
 			}
-			fmt.Fprintf(out, "  %s%s\n", path.Base(entry.Remote()), flag)
+			_, _ = fmt.Fprintf(out, "  %s%s\n", path.Base(entry.Remote()), flag)
 		}
 	}
 	return out.String()
diff --git a/lib/oauthutil/oauthutil.go b/lib/oauthutil/oauthutil.go
index 23c286683..cb3137baa 100644
--- a/lib/oauthutil/oauthutil.go
+++ b/lib/oauthutil/oauthutil.go
@@ -432,19 +432,19 @@ func (s *authServer) Start() {
 			state := req.FormValue("state")
 			if state != s.state {
 				fs.Debugf(nil, "State did not match: want %q got %q", s.state, state)
-				fmt.Fprintf(w, "<h1>Failure</h1>\n<p>Auth state doesn't match</p>")
+				_, _ = fmt.Fprintf(w, "<h1>Failure</h1>\n<p>Auth state doesn't match</p>")
 			} else {
 				fs.Debugf(nil, "Successfully got code")
 				if s.code != nil {
-					fmt.Fprintf(w, "<h1>Success</h1>\n<p>Go back to rclone to continue</p>")
+					_, _ = fmt.Fprintf(w, "<h1>Success</h1>\n<p>Go back to rclone to continue</p>")
 				} else {
-					fmt.Fprintf(w, "<h1>Success</h1>\n<p>Cut and paste this code into rclone: <code>%s</code></p>", code)
+					_, _ = fmt.Fprintf(w, "<h1>Success</h1>\n<p>Cut and paste this code into rclone: <code>%s</code></p>", code)
 				}
 			}
 		} else {
 			fs.Debugf(nil, "No code found on request")
 			w.WriteHeader(500)
-			fmt.Fprintf(w, "<h1>Failed!</h1>\nNo code found returned by remote server.")
+			_, _ = fmt.Fprintf(w, "<h1>Failed!</h1>\nNo code found returned by remote server.")
 		}
 		if s.code != nil {
 			s.code <- code