spring-projects / spring-integration-extensions

The Spring Integration Extensions project provides extension components for Spring Integration
http://www.springintegration.org/
280 stars 266 forks source link

zip: Exception during unzip deletes original file if deleteFiles is true. #242

Closed asegarra closed 3 years ago

asegarra commented 3 years ago

I found it odd that an exception being thrown from the unzipping process would still delete the original file making the situation a bit unexpected, I would have expected the deletion to occur only if the unzip was successful.

artembilan commented 3 years ago

Yes, I see your point:

    finally {
                IOUtils.closeQuietly(inputStream);
                if (payload instanceof File && this.deleteFiles) {
                    final File filePayload = (File) payload;
                    if (!filePayload.delete() && logger.isWarnEnabled()) {
                        if (logger.isWarnEnabled()) {
                            logger.warn("failed to delete File '" + filePayload + "'");
                        }
                    }
                }
            }

it is really not OK to delete in the finally when exception may happen in the main code.

Feel free to contribute the fix.

Thank you for catching this and raising an issue!