mirror of
https://github.com/owncast/owncast.git
synced 2024-11-22 04:40:37 +03:00
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:
parent
050028e72d
commit
c9298def5b
1 changed files with 14 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue