mirror of
https://github.com/apache/struts.git
synced 2026-08-05 14:47:09 +00:00
WW-5616 - JakartaStreamMultiPartRequest warns on file delete if the file doesnt exist (#1591)
* Pull aspects into alignment with main/7.x+ AbstractMultiPartRequest.java * Update JakartaMultiPartRequest and JakartaStreamMultiPartRequest to use isFile() * Update cleanup text to mirror main/7.x+
This commit is contained in:
+8
-4
@@ -373,10 +373,14 @@ public class JakartaMultiPartRequest extends AbstractMultiPartRequest {
|
||||
if (item instanceof DiskFileItem) {
|
||||
DiskFileItem diskItem = (DiskFileItem) item;
|
||||
File storeLocation = diskItem.getStoreLocation();
|
||||
if (storeLocation != null && storeLocation.exists()) {
|
||||
LOG.debug("Deleting temporary file: [{}]", storeLocation.getName());
|
||||
if (!storeLocation.delete()) {
|
||||
LOG.warn("Unable to delete temporary file: [{}]", storeLocation.getName());
|
||||
if (storeLocation != null) {
|
||||
if(storeLocation.isFile()) {
|
||||
LOG.debug("Deleting file: {}", storeLocation.getName());
|
||||
if (!storeLocation.delete()) {
|
||||
LOG.warn("There was a problem attempting to delete file: {}", storeLocation.getName());
|
||||
}
|
||||
} else {
|
||||
LOG.debug("File: {} already deleted", storeLocation.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-4
@@ -79,10 +79,16 @@ public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest {
|
||||
try {
|
||||
// catch any exceptions during cleanup to ensure all files are deleted.
|
||||
File file = fileInfo.getFile();
|
||||
LOG.debug("Deleting file '{}'.", file.getName());
|
||||
if (!file.delete()) {
|
||||
LOG.warn("There was a problem attempting to delete file [{}].",
|
||||
file.getName());
|
||||
if(file != null) {
|
||||
if(file.isFile()) {
|
||||
LOG.debug("Deleting file: {}", file.getName());
|
||||
if (!file.delete()) {
|
||||
LOG.warn("There was a problem attempting to delete file: {}",
|
||||
file.getName());
|
||||
}
|
||||
} else {
|
||||
LOG.debug("File: {} already deleted", file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Error during cleanup of file item: [{}]", normalizeSpace(fileInfo.getOriginalName()), e);
|
||||
|
||||
Reference in New Issue
Block a user