record: fix deleting segments in case of relative paths (#2526) (#2673)

This commit is contained in:
Alessandro Ros 2023-11-10 16:03:04 +01:00 committed by GitHub
parent ef19552632
commit d51baa04f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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