fixing file close problems

This commit is contained in:
aluvare
2021-12-06 21:45:05 +01:00
parent 963cf67602
commit aad66f586f

View File

@@ -342,19 +342,21 @@ func recorder(c *cli.Context) error {
logrus.Error("os.Open", err) logrus.Error("os.Open", err)
return return
} }
defer file.Close()
fileStat, err := file.Stat() fileStat, err := file.Stat()
if err != nil { if err != nil {
logrus.Error("fileStat", err) logrus.Error("fileStat", err)
file.Close()
return return
} }
uploadInfo, err := minioClient.PutObject(context.Background(), c.String("s3_bucketName"), outfileName + ".mp4", file, fileStat.Size(), minio.PutObjectOptions{ContentType:"application/octet-stream"}) uploadInfo, err := minioClient.PutObject(context.Background(), c.String("s3_bucketName"), outfileName + ".mp4", file, fileStat.Size(), minio.PutObjectOptions{ContentType:"application/octet-stream"})
if err != nil { if err != nil {
logrus.Error("minioClient.PutObject", err) logrus.Error("minioClient.PutObject", err)
file.Close()
return return
} else { } else {
file.Close()
os.Remove(outfileName + ".mp4") os.Remove(outfileName + ".mp4")
} }
logrus.Debug("Successfully uploaded bytes: ", uploadInfo) logrus.Debug("Successfully uploaded bytes: ", uploadInfo)