More linter fixes

This commit is contained in:
Kovid Goyal
2023-09-20 08:38:18 +05:30
parent d16a29b942
commit 18e5b74699
3 changed files with 22 additions and 17 deletions

View File

@@ -57,12 +57,13 @@ func RunSSHAskpass() {
fatal(fmt.Errorf("Failed to create SHM file with error: %w", err))
}
defer data_shm.Close()
defer data_shm.Unlink()
defer func() { _ = data_shm.Unlink() }()
data_shm.Slice()[0] = 0
shm.WriteWithSize(data_shm, data, 1)
err = data_shm.Flush()
if err != nil {
if err = shm.WriteWithSize(data_shm, data, 1); err != nil {
fatal(fmt.Errorf("Failed to write to SHM file with error: %w", err))
}
if err = data_shm.Flush(); err != nil {
fatal(fmt.Errorf("Failed to flush SHM file with error: %w", err))
}
trigger_ask(data_shm.Name())

View File

@@ -169,7 +169,7 @@ func get_arcname(loc, dest, home string) (arcname string) {
arcname = dest
} else {
arcname = filepath.Clean(loc)
if filepath.HasPrefix(arcname, home) {
if strings.HasPrefix(arcname, home) {
ra, err := filepath.Rel(home, arcname)
if err == nil {
arcname = ra

View File

@@ -154,7 +154,7 @@ func set_askpass() (need_to_request_data bool) {
sentinel_exists := err == nil
if sentinel_exists || GetSSHVersion().SupportsAskpassRequire() {
if !sentinel_exists {
os.WriteFile(sentinel, []byte{0}, 0o644)
_ = os.WriteFile(sentinel, []byte{0}, 0o644)
}
need_to_request_data = false
}
@@ -321,9 +321,13 @@ func make_tarfile(cd *connection_data, get_local_env func(string) (string, bool)
return nil
}
add_data(fe{"data.sh", utils.UnsafeStringToBytes(env_script)})
if err = add_data(fe{"data.sh", utils.UnsafeStringToBytes(env_script)}); err != nil {
return nil, err
}
if cd.script_type == "sh" {
add_data(fe{"bootstrap-utils.sh", shell_integration.Data()[path.Join("shell-integration/ssh/bootstrap-utils.sh")].Data})
if err = add_data(fe{"bootstrap-utils.sh", shell_integration.Data()[path.Join("shell-integration/ssh/bootstrap-utils.sh")].Data}); err != nil {
return nil, err
}
}
if ksi != "" {
for _, fname := range shell_integration.Data().FilesMatching(
@@ -546,7 +550,7 @@ func drain_potential_tty_garbage(term *tty.Term) {
buf := make([]byte, 0, 8192)
for !bytes.Contains(data, q) {
buf = buf[:cap(buf)]
timeout := give_up_at.Sub(time.Now())
timeout := time.Until(give_up_at)
if timeout < 0 {
break
}
@@ -596,7 +600,7 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro
defer func() {
if data_shm != nil {
data_shm.Close()
data_shm.Unlink()
_ = data_shm.Unlink()
}
}()
cmd := append([]string{SSHExe()}, ssh_args...)
@@ -702,9 +706,9 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro
c.Stdout = &b
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
return 1, fmt.Errorf("%s\nSetup of port forward in SSH ControlMaster failed with error: %w", string(b.Bytes()), err)
return 1, fmt.Errorf("%s\nSetup of port forward in SSH ControlMaster failed with error: %w", b.String(), err)
}
port, err := strconv.Atoi(strings.TrimSpace(string(b.Bytes())))
port, err := strconv.Atoi(strings.TrimSpace(b.String()))
if err != nil {
os.Stderr.Write(b.Bytes())
return 1, fmt.Errorf("Setup of port forward in SSH ControlMaster failed with error: invalid resolved port returned: %s", b.String())
@@ -731,7 +735,7 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro
restore_escape_codes += "\x1b[#Q"
}
defer func() {
term.WriteAllString(restore_escape_codes)
_ = term.WriteAllString(restore_escape_codes)
term.RestoreAndClose()
}()
err = get_remote_command(&cd)
@@ -759,13 +763,13 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro
}
}
if err != nil {
c.Process.Kill()
c.Wait()
_ = c.Process.Kill()
_ = c.Wait()
return 1, err
}
}
go func() {
_ = <-sigs
<-sigs
// ignore any interrupt and terminate signals as they will usually be sent to the ssh child process as well
// and we are waiting on that.
}()
@@ -776,7 +780,7 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro
var exit_err *exec.ExitError
if errors.As(err, &exit_err) {
if state := exit_err.ProcessState.String(); state == "signal: interrupt" {
unix.Kill(os.Getpid(), unix.SIGINT)
_ = unix.Kill(os.Getpid(), unix.SIGINT)
// Give the signal time to be delivered
time.Sleep(20 * time.Millisecond)
}