Skip to content

Commit

Permalink
Add GetProcess method to expose the underlying os.Process
Browse files Browse the repository at this point in the history
  • Loading branch information
bougou committed Aug 26, 2023
1 parent 2ee1a8c commit 11b254f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 11 additions & 2 deletions rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,17 @@ func (r Rsync) Run() error {
return r.cmd.Wait()
}

func (r Rsync) Cmd() *exec.Cmd {
return r.cmd
// GetProcess return the underlying os process.
//
// The caller can use this method to get information of the process or send signals
// to the rsync process like killing it.
//
// The caller should call this method only after Run is called.
func (r Rsync) GetProcess() *os.Process {
if r.cmd != nil {
return r.cmd.Process
}
return nil
}

// NewRsync returns task with described options
Expand Down
11 changes: 8 additions & 3 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"io"
"math"
"os/exec"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -80,8 +80,13 @@ func (t *Task) Run() error {
return err
}

func (r Task) Cmd() *exec.Cmd {
return r.rsync.cmd
func (r *Task) GetProcess() *os.Process {
if r.rsync != nil {
if r.rsync.cmd != nil {
return r.rsync.cmd.Process
}
}
return nil
}

// NewTask returns new rsync task
Expand Down

0 comments on commit 11b254f

Please sign in to comment.