fix: share local hls file cleanup between s3 and filesystem providers. Fixes #3522 (#3531)

This commit is contained in:
Gabe Kangas
2024-01-22 20:26:36 -08:00
committed by GitHub
parent 8a90e86c5b
commit 841c300431
3 changed files with 51 additions and 42 deletions

View File

@@ -202,19 +202,23 @@ func (s *S3Storage) Save(filePath string, retryCount int) (string, error) {
return s.Save(filePath, retryCount+1)
}
// Upload failure. Remove the local file.
s.removeLocalFile(filePath)
return "", fmt.Errorf("Giving up uploading %s to object storage %s", filePath, s.s3Endpoint)
}
// Upload success. Remove the local file.
s.removeLocalFile(filePath)
return response.Location, nil
}
// Cleanup will fire the different cleanup tasks required.
func (s *S3Storage) Cleanup() error {
if err := s.RemoteCleanup(); err != nil {
log.Errorln(err)
}
return localCleanup(4)
}
// RemoteCleanup will remove old files from the remote storage provider.
func (s *S3Storage) RemoteCleanup() error {
// Determine how many files we should keep on S3 storage
maxNumber := data.GetStreamLatencyLevel().SegmentCount
buffer := 20
@@ -276,14 +280,6 @@ func (s *S3Storage) getDeletableVideoSegmentsWithOffset(offset int) ([]s3object,
return objectsToDelete, nil
}
func (s *S3Storage) removeLocalFile(filePath string) {
cleanFilepath := filepath.Clean(filePath)
if err := os.Remove(cleanFilepath); err != nil {
log.Errorln(err)
}
}
func (s *S3Storage) deleteObjects(objects []s3object) {
keys := make([]*s3.ObjectIdentifier, len(objects))
for i, object := range objects {