Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

media upload cleanup bug #1423

Closed
gabriel-vasile opened this issue Aug 2, 2023 · 1 comment
Closed

media upload cleanup bug #1423

gabriel-vasile opened this issue Aug 2, 2023 · 1 comment
Labels
bug Something isn't working refactor Code refactor or cleanup with no functional changes

Comments

@gabriel-vasile
Copy link
Contributor

listmonk/cmd/media.go

Lines 62 to 85 in a440b79

fName, err = app.media.Put(fName, contentType, src)
if err != nil {
app.log.Printf("error uploading file: %v", err)
cleanUp = true
return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("media.errorUploading", "error", err.Error()))
}
var (
thumbfName = ""
width = 0
height = 0
)
defer func() {
// If any of the subroutines in this function fail,
// the uploaded image should be removed.
if cleanUp {
app.media.Delete(fName)
if thumbfName != "" {
app.media.Delete(thumbfName)
}
}
}()

when err != nil in this code there should be cleanup done, but the cleanup function has not been yet deferred.

@gabriel-vasile gabriel-vasile added the bug Something isn't working label Aug 2, 2023
@knadh knadh closed this as completed in e89b9ff Aug 3, 2023
@knadh knadh added the refactor Code refactor or cleanup with no functional changes label Aug 3, 2023
@knadh
Copy link
Owner

knadh commented Aug 3, 2023

Ah, removed that redundant flag. That error happens when the file upload itself has failed, in which case, there's no file to cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working refactor Code refactor or cleanup with no functional changes
Projects
None yet
Development

No branches or pull requests

2 participants