img: delete file on error

This commit is contained in:
stefanodvx 2025-04-15 16:20:02 +02:00
parent c06c7958e2
commit 8d972ff74b

View file

@ -37,6 +37,7 @@ func ImgToJPEG(file io.ReadSeeker, outputPath string) error {
if format == "jpeg" { if format == "jpeg" {
if _, err = file.Seek(0, io.SeekStart); err != nil { if _, err = file.Seek(0, io.SeekStart); err != nil {
os.Remove(outputPath)
return fmt.Errorf("failed to reset file position: %w", err) return fmt.Errorf("failed to reset file position: %w", err)
} }
@ -48,11 +49,13 @@ func ImgToJPEG(file io.ReadSeeker, outputPath string) error {
} }
if _, err = file.Seek(0, io.SeekStart); err != nil { if _, err = file.Seek(0, io.SeekStart); err != nil {
os.Remove(outputPath)
return fmt.Errorf("failed to reset file position: %w", err) return fmt.Errorf("failed to reset file position: %w", err)
} }
img, _, err := image.Decode(file) img, _, err := image.Decode(file)
if err != nil { if err != nil {
os.Remove(outputPath)
return fmt.Errorf("failed to decode image: %w", err) return fmt.Errorf("failed to decode image: %w", err)
} }