Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading