Skip to content

Commit

Permalink
record: fix deleting segments in case of relative paths (#2526) (#2673)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Nov 10, 2023
1 parent ef19552 commit d51baa0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/record/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -130,31 +134,31 @@ 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)
}
}
}

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
Expand Down

0 comments on commit d51baa0

Please sign in to comment.