提交 327e7615 编写于 作者: A Arjen Poutsma

Recreate file storage directory when removed in DefaultPartHttpMessageReader

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 gh-26790
上级 4e42b5df
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -20,6 +20,7 @@ import java.io.IOException; ...@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel; import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
...@@ -53,7 +54,7 @@ import org.springframework.util.FastByteArrayOutputStream; ...@@ -53,7 +54,7 @@ import org.springframework.util.FastByteArrayOutputStream;
/** /**
* Subscribes to a token stream (i.e. the result of * 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 * @author Arjen Poutsma
* @since 5.3 * @since 5.3
...@@ -577,6 +578,9 @@ final class PartGenerator extends BaseSubscriber<MultipartParser.Token> { ...@@ -577,6 +578,9 @@ final class PartGenerator extends BaseSubscriber<MultipartParser.Token> {
private WritingFileState createFileState(Path directory) { private WritingFileState createFileState(Path directory) {
try { try {
if (!Files.exists(directory)) {
Files.createDirectory(directory);
}
Path tempFile = Files.createTempFile(directory, null, ".multipart"); Path tempFile = Files.createTempFile(directory, null, ".multipart");
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Storing multipart data in file " + tempFile); logger.trace("Storing multipart data in file " + tempFile);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册