Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Cleanup object storage files on success or failure (#3231)

Gabe Kangascf5496ed84b2
diff --git a/core/storageproviders/s3Storage.go b/core/storageproviders/s3Storage.go
index cef3816933..72c6aa3329 100644
--- a/core/storageproviders/s3Storage.go
+++ b/core/storageproviders/s3Storage.go
@@ -184,9 +184,15 @@ 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
}
@@ -252,6 +258,14 @@ 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 {