From 11b254f465bda6dda262225f2f0922e91208cd7e Mon Sep 17 00:00:00 2001 From: Bougou Date: Sat, 26 Aug 2023 16:46:47 +0800 Subject: [PATCH] Add GetProcess method to expose the underlying os.Process --- rsync.go | 13 +++++++++++-- task.go | 11 ++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/rsync.go b/rsync.go index 2602eef..c824b20 100644 --- a/rsync.go +++ b/rsync.go @@ -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 diff --git a/task.go b/task.go index cd7fa5a..866d9df 100644 --- a/task.go +++ b/task.go @@ -5,7 +5,7 @@ import ( "bytes" "io" "math" - "os/exec" + "os" "strconv" "strings" "sync" @@ -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