mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-03 12:58:57 +01:00
zfscmd: do not do duplicate waitPre callbacks
it just makes sense that if we only dispatch one waitPost, we should also only dispatch one waitPre
This commit is contained in:
parent
f61295f76c
commit
0834a184b8
@ -18,10 +18,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Cmd struct {
|
type Cmd struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
startedAt, waitReturnedAt time.Time
|
startedAt, waitStartedAt, waitReturnedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommandContext(ctx context.Context, name string, arg ...string) *Cmd {
|
func CommandContext(ctx context.Context, name string, arg ...string) *Cmd {
|
||||||
@ -119,13 +119,30 @@ func (c *Cmd) startPost(err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cmd) waitPre() {
|
func (c *Cmd) waitPre() {
|
||||||
waitPreLogging(c, time.Now())
|
now := time.Now()
|
||||||
|
|
||||||
|
// ignore duplicate waits
|
||||||
|
c.mtx.Lock()
|
||||||
|
// ignore duplicate waits
|
||||||
|
if !c.waitStartedAt.IsZero() {
|
||||||
|
c.mtx.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.waitStartedAt = now
|
||||||
|
c.mtx.Unlock()
|
||||||
|
|
||||||
|
waitPreLogging(c, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cmd) waitPost(err error) {
|
func (c *Cmd) waitPost(err error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
|
// ignore duplicate waits
|
||||||
|
if !c.waitReturnedAt.IsZero() {
|
||||||
|
c.mtx.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
c.waitReturnedAt = now
|
c.waitReturnedAt = now
|
||||||
c.mtx.Unlock()
|
c.mtx.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user