Skip to content

Commit

Permalink
Merge pull request #1115 from wakatime/develop
Browse files Browse the repository at this point in the history
Release v1.102.5
  • Loading branch information
gandarez authored Oct 31, 2024
2 parents fad2841 + e9a9451 commit 04fb85a
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions pkg/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

const (
defaultTimeoutSecs = 20
// Max file size supporting downloading from remote. Default is 512Kb.
// maxFileSize defines the max file size to download from remote. Default is 512Kb.
maxFileSize = 512000
defaultPort = 22
)
Expand All @@ -52,31 +52,17 @@ func WithDetection() heartbeat.HandleOption {
return func(hh []heartbeat.Heartbeat) ([]heartbeat.Result, error) {
log.Debugln("execute remote file detection")

var (
tmpDir string
err error
filtered []heartbeat.Heartbeat
)
var filtered []heartbeat.Heartbeat

for _, h := range hh {
if !h.IsRemote() {
filtered = append(filtered, h)
continue
}

if tmpDir == "" {
tmpDir, err = os.MkdirTemp(os.TempDir(), "")
if err != nil {
log.Errorf("failed to create temporary directory: %s", err)

continue
}
}

tmpFile, err := os.CreateTemp(tmpDir, fmt.Sprintf("*%s", filepath.Base(h.Entity)))
tmpFile, err := os.CreateTemp("", fmt.Sprintf("*_%s", filepath.Base(h.Entity)))
if err != nil {
log.Errorf("failed to create temporary file: %s", err)

continue
}

Expand Down Expand Up @@ -134,8 +120,8 @@ func WithCleanup() heartbeat.HandleOption {
}
}

func deleteLocalFile(file string) {
err := os.Remove(file)
func deleteLocalFile(fp string) {
err := os.Remove(fp)
if err != nil {
log.Warnf("unable to delete tmp file: %s", err)
}
Expand Down Expand Up @@ -165,11 +151,13 @@ func NewClient(address string) (Client, error) {
}

if port == 0 {
port, _ = strconv.Atoi(ssh_config.Get(host, "Port"))
port, err = strconv.Atoi(ssh_config.Get(host, "Port"))
log.Warnf("failed to parse port from host: %s", err)
}

if port == 0 {
port, _ = strconv.Atoi(ssh_config.Get(derivedHost, "Port"))
port, err = strconv.Atoi(ssh_config.Get(derivedHost, "Port"))
log.Warnf("failed to parse port from derived host: %s", err)
}

if port == 0 {
Expand Down Expand Up @@ -541,12 +529,12 @@ func hostKeyAlias(hostOriginal string, hostDerived string) string {
return ""
}

aliasExpanded, err := homedir.Expand(alias)
alias, err := homedir.Expand(alias)
if err != nil {
log.Debugf("Unable to expand home directory for HostKeyAlias %s: %w", alias, err)
log.Debugf("Unable to expand home directory for HostKeyAlias %q: %w", alias, err)
}

return aliasExpanded
return alias
}

// contains returns true if any case-insensitive arg is found in the list of values.
Expand Down

0 comments on commit 04fb85a

Please sign in to comment.