From d51baa04f7f3131a5302de4bfb2fd4d6689296d2 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Fri, 10 Nov 2023 16:03:04 +0100 Subject: [PATCH] record: fix deleting segments in case of relative paths (#2526) (#2673) --- internal/record/cleaner.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/record/cleaner.go b/internal/record/cleaner.go index 39662362..8d0620d6 100644 --- a/internal/record/cleaner.go +++ b/internal/record/cleaner.go @@ -119,6 +119,10 @@ func (c *Cleaner) doRun() { func (c *Cleaner) doRunEntry(e *CleanerEntry) error { recordPath := e.RecordPath + // we have to convert to absolute paths + // otherwise, commonPath and fpath inside Walk() won't have common elements + recordPath, _ = filepath.Abs(recordPath) + switch e.RecordFormat { case conf.RecordFormatMPEGTS: recordPath += ".ts" @@ -130,17 +134,17 @@ func (c *Cleaner) doRunEntry(e *CleanerEntry) error { commonPath := commonPath(recordPath) now := timeNow() - filepath.Walk(commonPath, func(path string, info fs.FileInfo, err error) error { //nolint:errcheck + filepath.Walk(commonPath, func(fpath string, info fs.FileInfo, err error) error { //nolint:errcheck if err != nil { return err } if !info.IsDir() { - params := decodeRecordPath(recordPath, path) + params := decodeRecordPath(recordPath, fpath) if params != nil { if now.Sub(params.time) > e.RecordDeleteAfter { - c.Log(logger.Debug, "removing %s", path) - os.Remove(path) + c.Log(logger.Debug, "removing %s", fpath) + os.Remove(fpath) } } } @@ -148,13 +152,13 @@ func (c *Cleaner) doRunEntry(e *CleanerEntry) error { return nil }) - filepath.Walk(commonPath, func(path string, info fs.FileInfo, err error) error { //nolint:errcheck + filepath.Walk(commonPath, func(fpath string, info fs.FileInfo, err error) error { //nolint:errcheck if err != nil { return err } if info.IsDir() { - os.Remove(path) + os.Remove(fpath) } return nil