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

* fix: cleanup object storage files on success or failure. Closes #3230

* fix: clean filepath when deleting for safety
This commit is contained in:
Gabe Kangas 2023-08-03 20:33:44 -07:00 committed by GitHub
parent 050028e72d
commit c9298def5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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