Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions get_smbclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
"time"
)

// SmbClientGetter is a Getter implementation that will download a module from
// a shared folder using smbclient cli.
type SmbClientGetter struct {

// Timeout sets a deadline which all smb client CLI operations should
// complete within. Defaults to zero which means no timeout.
Timeout time.Duration
// Timeout in seconds sets a deadline which all smb client CLI operations should
// complete within. Defaults to zero which means to use the default client timeout of 20 seconds.
Timeout int
}

func (g *SmbClientGetter) Mode(ctx context.Context, u *url.URL) (Mode, error) {
Expand Down Expand Up @@ -222,6 +222,10 @@ func (g *SmbClientGetter) smbclientCmdArgs(used *url.Userinfo, hostPath string,
baseCmd = append(baseCmd, hostPath)
baseCmd = append(baseCmd, "--directory")
baseCmd = append(baseCmd, fileDir)
if g.Timeout > 0 {
baseCmd = append(baseCmd, "-t")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

baseCmd = append(baseCmd, strconv.Itoa(g.Timeout))
}
return baseCmd
}

Expand Down Expand Up @@ -261,13 +265,6 @@ func (g *SmbClientGetter) isDirectory(args []string, object string) (bool, error

func (g *SmbClientGetter) runSmbClientCommand(dst string, args []string) (string, error) {
ctx := context.Background()

if g.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), g.Timeout)
defer cancel()
}

cmd := exec.CommandContext(ctx, "smbclient", args...)

if dst != "" {
Expand Down