Skip to content

Commit

Permalink
Recreate file storage directory when removed in DefaultPartHttpMessag…
Browse files Browse the repository at this point in the history
…eReader

Some operating systems delete temp files not just when booting up, but
also during operation. This commit makes sure that the
DefaultPartHttpMessageReader recreates the directory used to store
files in, if it's not there.

Closes spring-projectsgh-26790
  • Loading branch information
poutsma authored and Zoran0104 committed Aug 20, 2021
1 parent 77eaf45 commit 50acabc
Showing 1 changed file with 6 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
Expand Down Expand Up @@ -53,7 +54,7 @@

/**
* Subscribes to a token stream (i.e. the result of
* {@link MultipartParser#parse(Flux, byte[], int)}, and produces a flux of {@link Part} objects.
* {@link MultipartParser#parse(Flux, byte[], int, Charset)}, and produces a flux of {@link Part} objects.
*
* @author Arjen Poutsma
* @since 5.3
Expand Down Expand Up @@ -577,6 +578,9 @@ public void createFile() {

private WritingFileState createFileState(Path directory) {
try {
if (!Files.exists(directory)) {
Files.createDirectory(directory);
}
Path tempFile = Files.createTempFile(directory, null, ".multipart");
if (logger.isTraceEnabled()) {
logger.trace("Storing multipart data in file " + tempFile);
Expand Down

0 comments on commit 50acabc

Please sign in to comment.