fix bug in updateTailPos, add Close() for tailers

This commit is contained in:
sawka 2022-06-16 22:23:29 -07:00
parent dc4baaea27
commit 3497f607ce
2 changed files with 11 additions and 6 deletions

View File

@ -44,14 +44,14 @@ func (w CmdWatchEntry) getTailPos(reqId string) (TailPos, bool) {
return TailPos{}, false
}
func (w *CmdWatchEntry) updateTailPos(reqId string, pos TailPos) {
func (w *CmdWatchEntry) updateTailPos(reqId string, newPos TailPos) {
for idx, pos := range w.Tails {
if pos.ReqId == reqId {
w.Tails[idx] = pos
w.Tails[idx] = newPos
return
}
}
w.Tails = append(w.Tails, pos)
w.Tails = append(w.Tails, newPos)
}
func (w *CmdWatchEntry) removeTailPos(reqId string) {
@ -284,6 +284,10 @@ func (t *Tailer) Run() error {
return err
}
func (t *Tailer) Close() error {
return t.Watcher.Close()
}
func max(v1 int64, v2 int64) int64 {
if v1 > v2 {
return v1
@ -304,9 +308,6 @@ func (entry *CmdWatchEntry) fillFilePos(scHomeDir string) {
}
func (t *Tailer) AddWatch(getPacket *packet.GetCmdPacketType) error {
if !getPacket.Tail {
return fmt.Errorf("cannot add a watch for non-tail packet")
}
_, err := uuid.Parse(getPacket.SessionId)
if err != nil {
return fmt.Errorf("getcmd, bad sessionid '%s': %w", getPacket.SessionId, err)

View File

@ -58,6 +58,10 @@ func MakeSessionWatcher() (*SessionWatcher, error) {
return rtn, nil
}
func (w *SessionWatcher) Close() error {
return w.Watcher.Close()
}
func (w *SessionWatcher) UnWatchSession(sessionId string) error {
_, err := uuid.Parse(sessionId)
if err != nil {