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
@ -184,9 +184,15 @@ func (s *S3Storage) Save(filePath string, retryCount int) (string, error) {
|
|||||||
return s.Save(filePath, retryCount+1)
|
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)
|
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
|
return response.Location, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +258,14 @@ func (s *S3Storage) getDeletableVideoSegmentsWithOffset(offset int) ([]s3object,
|
|||||||
return objectsToDelete, nil
|
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) {
|
func (s *S3Storage) deleteObjects(objects []s3object) {
|
||||||
keys := make([]*s3.ObjectIdentifier, len(objects))
|
keys := make([]*s3.ObjectIdentifier, len(objects))
|
||||||
for i, object := range objects {
|
for i, object := range objects {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user